BAT file to re-start in Safe Mode...?

  • Thread starter Thread starter Kenneth
  • Start date Start date
K

Kenneth

Howdy,

I have a simple batch file that dumps 4000 contacts from my
database to a TXT file, and then imports them to my
Contacts.

Recently, that last phase has been producing some errors
indicating a problem with the command line text that does
the import. This happens intermittently.

The folks who support the importing software (Contact Genie)
tell me that the command line text is fine (as I would
assume because it usually works properly), and they believe
that something is corrupting the command line text
preventing their software from correctly interpreting it...

I have experimented with the simple work-around of running
the BAT file in Safe Mode with Networking, and this seems to
work.

So, with all that as introduction, here is my question:

Is there a way for me to modify the BAT file so that it
says, in effect, "re-boot into Safe Mode with Networking,
run this routine, then re-boot into full XP?"

Many thanks for any help on this,
 
Kenneth said:
Howdy,

I have a simple batch file that dumps 4000 contacts from my
database to a TXT file, and then imports them to my
Contacts.

Recently, that last phase has been producing some errors
indicating a problem with the command line text that does
the import. This happens intermittently.

The folks who support the importing software (Contact Genie)
tell me that the command line text is fine (as I would
assume because it usually works properly), and they believe
that something is corrupting the command line text
preventing their software from correctly interpreting it...

I have experimented with the simple work-around of running
the BAT file in Safe Mode with Networking, and this seems to
work.

So, with all that as introduction, here is my question:

Is there a way for me to modify the BAT file so that it
says, in effect, "re-boot into Safe Mode with Networking,
run this routine, then re-boot into full XP?"

Many thanks for any help on this,

If a program works in Safe Mode but fails in Normal Mode then you have an
agent running in Safe Mode that intereferes with your program. The usual
method to resolve this problem is based on isolating and removing the
interfering agent.

To boot into safe mode, you need to maintain two versions of the hidden file
c:\boot.ini, e.g. c:\boot.norm and c:\boot.safe. The file c:\boot.safe
should have this line:
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP
Professional" /fastdetect /noexecute=optin /safeboot:minimal
whereas the file c:\boot.norm lacks the /safeboot:minimal switch.

You also need a batch file c:\windows\MyBoot.bat with these lines inside:
@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.safe c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.norm c:\boot.ini
)

And here is how you put it all together:

1. Create a shortcut on your desktop. Call it "Boot into Safe Mode" and
point it at c:\windows\MyBoot.bat with a parameter of "Safe" (without the
double quotes!).
2. Create a scheduled task. It should invoke c:\windows\MyBoot.bat and it
must run at boot time.

That's all. Now each time you double-click "Boot into Safe Mode", the
machine will reboot in Safe Mode. The next time it will boot normally.

Enjoy!
 
If a program works in Safe Mode but fails in Normal Mode then you have an
agent running in Safe Mode that intereferes with your program. The usual
method to resolve this problem is based on isolating and removing the
interfering agent.

To boot into safe mode, you need to maintain two versions of the hidden file
c:\boot.ini, e.g. c:\boot.norm and c:\boot.safe. The file c:\boot.safe
should have this line:
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP
Professional" /fastdetect /noexecute=optin /safeboot:minimal
whereas the file c:\boot.norm lacks the /safeboot:minimal switch.

You also need a batch file c:\windows\MyBoot.bat with these lines inside:
@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.safe c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.norm c:\boot.ini
)

And here is how you put it all together:

1. Create a shortcut on your desktop. Call it "Boot into Safe Mode" and
point it at c:\windows\MyBoot.bat with a parameter of "Safe" (without the
double quotes!).
2. Create a scheduled task. It should invoke c:\windows\MyBoot.bat and it
must run at boot time.

That's all. Now each time you double-click "Boot into Safe Mode", the
machine will reboot in Safe Mode. The next time it will boot normally.

Enjoy!

Hello again,

Many thanks for the great help...!

I realize now that I neglected to say that I need Safe Mode
with Networking.

What modification would I need for that?

All the best,
 
Hi again,

With some sniffing around, it seems that instead of:

/safeboot:minimal

I would use

/safeboot:network

Would that do the deed?

Thanks again,
 
If a program works in Safe Mode but fails in Normal Mode then you have an
agent running in Safe Mode that intereferes with your program. The usual
method to resolve this problem is based on isolating and removing the
interfering agent.

To boot into safe mode, you need to maintain two versions of the hidden file
c:\boot.ini, e.g. c:\boot.norm and c:\boot.safe. The file c:\boot.safe
should have this line:
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP
Professional" /fastdetect /noexecute=optin /safeboot:minimal
whereas the file c:\boot.norm lacks the /safeboot:minimal switch.

You also need a batch file c:\windows\MyBoot.bat with these lines inside:
@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.safe c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.norm c:\boot.ini
)

And here is how you put it all together:

1. Create a shortcut on your desktop. Call it "Boot into Safe Mode" and
point it at c:\windows\MyBoot.bat with a parameter of "Safe" (without the
double quotes!).
2. Create a scheduled task. It should invoke c:\windows\MyBoot.bat and it
run at boot time.

That's all. Now each time you double-click "Boot into Safe Mode", the
machine will reboot in Safe Mode. The next time it will boot normally.

Enjoy!

Hi Pegasus,

There is one thing in your suggestion that I don't
understand...

You wrote:

1. Create a shortcut on your desktop. Call it "Boot into
Safe Mode" and point it at c:\windows\MyBoot.bat with a
parameter of "Safe"
double quotes!).

but I don't know how to add the Safe parameter.

Also, I need Safe with Networking, so in any case I need a
bit more information.

Many thanks,
 
Kenneth said:
Hi Pegasus,

There is one thing in your suggestion that I don't
understand...

You wrote:

1. Create a shortcut on your desktop. Call it "Boot into
Safe Mode" and point it at c:\windows\MyBoot.bat with a
parameter of "Safe"

but I don't know how to add the Safe parameter.

Also, I need Safe with Networking, so in any case I need a
bit more information.

Many thanks,

After creating the shortcut, right-click it, then click "Properties". Now
add a space to the far end in the "Target" box and type "Safe". It's as
simple as that!

You previously wrote that you found the switch "/safeboot:network" after
some sniffing about. This sounds quite reasonable. I suggest you try it out.
If it does not work, do some more sniffing and report the result here - I
would have to do the same thing too!
 
After creating the shortcut, right-click it, then click "Properties". Now
add a space to the far end in the "Target" box and type "Safe". It's as
simple as that!

You previously wrote that you found the switch "/safeboot:network" after
some sniffing about. This sounds quite reasonable. I suggest you try it out.
If it does not work, do some more sniffing and report the result here - I
would have to do the same thing too!

Hi again,

I modified the Target as per your description, and the
shortcut points to:

@echo off if /i "%1"=="Safe" (copy /y c:\boot.safe
c:\boot.ini shutdown /.. /..) else
(copy /y c:\boot.norm c:\boot.ini)


I have the other bat files just as you have described.

But, when I fire up the shortcut, all that happens is a
momentary flash of the command line. The system does not
reboot.

That is true whether I set the shortcut target parameter to
safe, or to safe:network.

In the hope that you might spot the problem, I will include
everything I have done.

C:\boot.norm consists of:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft
Windows XP Professional" /noexecute=optin /fastdetect

(I just pasted in my present boot.ini. Was that what you
intended?)



C:\boot.safe consists of:

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft
Windows XP Professional" /fastdetect /noexecute=optin
/safeboot:network




c:\windows\MyBoot.bat consists of:

@echo off if /i "%1"=="Safe" (copy /y c:\boot.safe
c:\boot.ini shutdown /.. /..) else
(copy /y c:\boot.norm c:\boot.ini)

(Does the above need the [boot loader] line?)


and finally, I have a scheduled task that calls
c:\windows\MyBoot.bat and runs at boot.

Sincere thanks for any further help,
 
Kenneth said:
After creating the shortcut, right-click it, then click "Properties". Now
add a space to the far end in the "Target" box and type "Safe". It's as
simple as that!

You previously wrote that you found the switch "/safeboot:network" after
some sniffing about. This sounds quite reasonable. I suggest you try it
out.
If it does not work, do some more sniffing and report the result here - I
would have to do the same thing too!

Hi again,

I modified the Target as per your description, and the
shortcut points to:

@echo off if /i "%1"=="Safe" (copy /y c:\boot.safe
c:\boot.ini shutdown /.. /..) else
(copy /y c:\boot.norm c:\boot.ini)


I have the other bat files just as you have described.

But, when I fire up the shortcut, all that happens is a
momentary flash of the command line. The system does not
reboot.

That is true whether I set the shortcut target parameter to
safe, or to safe:network.

In the hope that you might spot the problem, I will include
everything I have done.

C:\boot.norm consists of:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft
Windows XP Professional" /noexecute=optin /fastdetect

(I just pasted in my present boot.ini. Was that what you
intended?)



C:\boot.safe consists of:

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft
Windows XP Professional" /fastdetect /noexecute=optin
/safeboot:network




c:\windows\MyBoot.bat consists of:

@echo off if /i "%1"=="Safe" (copy /y c:\boot.safe
c:\boot.ini shutdown /.. /..) else
(copy /y c:\boot.norm c:\boot.ini)

(Does the above need the [boot loader] line?)


and finally, I have a scheduled task that calls
c:\windows\MyBoot.bat and runs at boot.

Sincere thanks for any further help,

I can see a few problems in your approach. Firstly, your batch file has the
lines broken up differently from the way I put them. Here is what I wrote:
@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.safe c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.norm c:\boot.ini
)
You must not take liberties when copying & pasting this file.

Secondly, the file c:\boot.safe must be an exact copy of the file
c:\boot.norm, with this switch added to the last line: /safeboot:network.

After making these changes, you MUST test your batch file. You do it in a
Command Prompt so that you can see what's going on. Here is how it's done:
1. Click Start/Run/cmd{OK}
2. Type the following commands:
type c:\boot.ini{Enter}
(Examine what you see on the screen)
MyBoot.bat Safe {Enter}
type c:\boot.ini(Enter)
(Examine the screen again. You should see the "/safeboot" switch.)
MyBoot.bat{Enter}
type c:\boot.ini{Enter}
(Examine the screen again. There should be no "/safeboot" switch.)
If there are error messages then you must make a note of them.
 
I can see a few problems in your approach. Firstly, your batch file has the
lines broken up differently from the way I put them. Here is what I wrote:
@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.safe c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.norm c:\boot.ini
)
You must not take liberties when copying & pasting this file.

Secondly, the file c:\boot.safe must be an exact copy of the file
c:\boot.norm, with this switch added to the last line: /safeboot:network.

After making these changes, you MUST test your batch file. You do it in a
Command Prompt so that you can see what's going on. Here is how it's done:
1. Click Start/Run/cmd{OK}
2. Type the following commands:
type c:\boot.ini{Enter}
(Examine what you see on the screen)
MyBoot.bat Safe {Enter}
type c:\boot.ini(Enter)
(Examine the screen again. You should see the "/safeboot" switch.)
MyBoot.bat{Enter}
type c:\boot.ini{Enter}
(Examine the screen again. There should be no "/safeboot" switch.)
If there are error messages then you must make a note of them.

Hi again Pegasus,

Many thanks for hangin' in there with me on this...

Indeed I had taken "liberties" with the text. I
(incorrectly) thought I was seeing some wrapping oddities. I
will redo it shortly.

All the best,
 
I can see a few problems in your approach. Firstly, your batch file has the
lines broken up differently from the way I put them. Here is what I wrote:
@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.safe c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.norm c:\boot.ini
)
You must not take liberties when copying & pasting this file.

Secondly, the file c:\boot.safe must be an exact copy of the file
c:\boot.norm, with this switch added to the last line: /safeboot:network.

After making these changes, you MUST test your batch file. You do it in a
Command Prompt so that you can see what's going on. Here is how it's done:
1. Click Start/Run/cmd{OK}
2. Type the following commands:
type c:\boot.ini{Enter}
(Examine what you see on the screen)
MyBoot.bat Safe {Enter}
type c:\boot.ini(Enter)
(Examine the screen again. You should see the "/safeboot" switch.)
MyBoot.bat{Enter}
type c:\boot.ini{Enter}
(Examine the screen again. There should be no "/safeboot" switch.)
If there are error messages then you must make a note of them.

Hi Pegasus,

I have made the modifications you describe (and this time,
strictly with cut & paste...)

When, at the command line, I enter C:\boot.ini, it displays
properly.

But, when, at the command line, I enter "MyBoot.bat Safe"
(without quotes), I get an access denied error.

I experimented with entering "MyBoot.bat", "MyBoot.bat
Safe:network" and got the same access denied error. I also
tried it these will full path as "C:\Windows\MyBoot.bat
Safe" but again, always have the same result.

Thanks for any further help,
 
Hi Pegasus,

I have made the modifications you describe (and this time,
strictly with cut & paste...)

When, at the command line, I enter C:\boot.ini, it displays
properly.

But, when, at the command line, I enter "MyBoot.bat Safe"
(without quotes), I get an access denied error.

I experimented with entering "MyBoot.bat", "MyBoot.bat
Safe:network" and got the same access denied error. I also
tried it these will full path as "C:\Windows\MyBoot.bat
Safe" but again, always have the same result.

Thanks for any further help,

Hi again Pegasus,

This might be of interest...

As I thought about this further, I decided to look at my
present boot.ini.

I could not find it in C:\ and so ran a Search (yes, my
hidden files are visible.)

The only instance found is in C:\Documents and
Settings\Kenneth\Recent.

The system boots fine, but it would appear that the bat
files are pointing to a boot.ini that does not exist.

Thanks again,
 
Kenneth said:
Hi again Pegasus,

This might be of interest...

As I thought about this further, I decided to look at my
present boot.ini.

I could not find it in C:\ and so ran a Search (yes, my
hidden files are visible.)

The only instance found is in C:\Documents and
Settings\Kenneth\Recent.

The system boots fine, but it would appear that the bat
files are pointing to a boot.ini that does not exist.

Thanks again,

The file c:\boot.ini is a hidden file. You must unhide it and remove its
read-only attribute before you can run my batch file. And no, don't believe
your search results. The file DOES exist in the root folder of drive C:. If
you cannot get Windows Explorer to show you where it is, use the
administrator's method: Open a Command Prompt (see my previous reply), then
type this command:

attrib -r -h -s c:\boot.ini {Enter}
 
The file c:\boot.ini is a hidden file. You must unhide it and remove its
read-only attribute before you can run my batch file. And no, don't believe
your search results. The file DOES exist in the root folder of drive C:. If
you cannot get Windows Explorer to show you where it is, use the
administrator's method: Open a Command Prompt (see my previous reply), then
type this command:

attrib -r -h -s c:\boot.ini {Enter}

Hi again Pegasus,

Well, it appears that we are almost there...

I have run the attrib, and now the bat file is working
properly in the sense that it modifies the boot.ini in the
intended ways.

If I run MyBoot.bat, and then manually re-boot the box, it
comes up in safe mode. If I then run MyBoot.bat again, and
re-boot, it comes up in normal mode.

But, when I attempt to run the shortcut to start the whole
process, I see only a very brief flash of a command screen
and nothing further happens, that is, there is no reboot.

Here is everything I have at this point:






On my desktop, I have a shortcut pointing to:

C:\WINDOWS\MyBoot.bat safe:network




MyBoot.bat is:

@echo off
if /i "%1"=="Safe" (
copy /y c:\boot.SAFE c:\boot.ini
shutdown /.. /..
) else (
copy /y c:\boot.NORM c:\boot.ini
)



boot.SAFE is:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft
Windows XP Professional" /noexecute=optin /fastdetect
/safeboot:network




boot.NORM is:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft
Windows XP Professional" /noexecute=optin /fastdetect



and I have a scheduled task that runs MyBoot.bat at startup.


I saw that in Myboot.bat the criterion is "Safe" but I am
attempting to run "Safe:Network." I tried switching it, but
still had the same result: brief flash, but no reboot.

Many thanks as before,
 
On Thu, 25 Sep 2008 12:59:52 -0400, Kenneth

Hi again,

If I run MyBoot.bat, and then manually re-boot the box, it
comes up in safe mode. If I then run MyBoot.bat again, and
re-boot, it comes up in normal mode.


but since then, I have tried it again.

Now, if I run MyBoot.bat, it shows 1 file copied, but does
not modify boot.ini, which remains in its normal mode.

If I repeat, exactly the same thing happens.

Sincere thanks,
 
Kenneth said:
On Thu, 25 Sep 2008 12:59:52 -0400, Kenneth

Hi again,




but since then, I have tried it again.

Now, if I run MyBoot.bat, it shows 1 file copied, but does
not modify boot.ini, which remains in its normal mode.

If I repeat, exactly the same thing happens.

Sincere thanks,

You need to acquire a better understanding of the process in order to debug
it. Consider the following points:
- MyBoot.bat does NOT modify c:\boot.ini. It replaces it.
- When you run "MyBoot.bat safe" then c:\boot.ini gets replaced by
c:\boot.safe.
- When you run "MyBoot.bat" then c:\boot.ini gets replaced by c:\boot.norm.

During the debugging phase, change the line "shutdown /.. /.." in MyBoot.bat
to "rem shutdown /.. /.." so that the machine does not reboot all the time.

Armed with the above knowledge you should be able to find out what's wrong.
The whole thing is not "black magic" but rather a "substitution racket" . .
..
 
You need to acquire a better understanding of the process in order to debug
it. Consider the following points:
- MyBoot.bat does NOT modify c:\boot.ini. It replaces it.
- When you run "MyBoot.bat safe" then c:\boot.ini gets replaced by
c:\boot.safe.
- When you run "MyBoot.bat" then c:\boot.ini gets replaced by c:\boot.norm.

During the debugging phase, change the line "shutdown /.. /.." in MyBoot.bat
to "rem shutdown /.. /.." so that the machine does not reboot all the time.

Armed with the above knowledge you should be able to find out what's wrong.
The whole thing is not "black magic" but rather a "substitution racket" . .
.

Hi Pegasus,

My wording was poor, but I did understand that MyBoot.bat
copies the appropriate version into boot.ini, that is,
replaces it.

You responded as if I had said that MyBoot.bat was causing
rebooting while I was attempting to debug.

The problem I am having now is that when I run MyBoot.bat,
it does NOT reboot the system at all.

Many thanks,
 
Kenneth said:
Hi Pegasus,

My wording was poor, but I did understand that MyBoot.bat
copies the appropriate version into boot.ini, that is,
replaces it.

You responded as if I had said that MyBoot.bat was causing
rebooting while I was attempting to debug.

The problem I am having now is that when I run MyBoot.bat,
it does NOT reboot the system at all.

Many thanks,

Sorry - can't tell. I left the exact composition of the "shutdown" command
to you and I get the impression that you never filled in the missing bits.
This command has a number of switches and you need to familiarise yourself
with them by typing shutdown /? at the Command Prompt.
 
Sorry - can't tell. I left the exact composition of the "shutdown" command
to you and I get the impression that you never filled in the missing bits.
This command has a number of switches and you need to familiarise yourself
with them by typing shutdown /? at the Command Prompt.

Hello again,

Indeed, I did not fill in the "missing bits" as I did not
know that there were any to be filled in.

I'll get on it, and will let you know.

Many thanks, as before,
 
Hello again,

Indeed, I did not fill in the "missing bits" as I did not
know that there were any to be filled in.

I'll get on it, and will let you know.

Many thanks, as before,

Hi again,

I entered the appropriate shutdown switches, and not the
shortcut causes the reboot into safe mode with networking.

Unfortunately, running it a second time leaves it in safe
mode, but before asking anything about that issue, I have
another question:

I had hoped to do all this because I have a BAT file that
invokes a process that often fails when run in normal mode.
If running in safe mode, it always runs properly.

I wanted to create a routine that would boot into safe mode,
run my BAT file, and when it finished, would re-boot back
into normal mode.

In all this, I had neglected the fact that when I enter safe
mode, I have to log in again, and have to enter my password.

Am I correct that there is no way that I could "bypass" that
part of the process? That is, am I correct that even if I
get this working correctly, I will still have to enter that
password manually?

Please let me know, and that will help me to decide if I
should pursue this further.

Many thanks,
 
Back
Top