Jump to content

Bat file not working, why?


5614

Recommended Posts

I started off with a command like this:

 

echo 
echo Restarting the pc in 10 seconds.....
shutdown.exe -r -f -t 10 -c "Windows XP will now restart in 10 seconds"

And I wanted to make it shutdown instead of reboot so I learnt to replace the -r with -s and I also found out that by using a command such as:

 

shutdown.exe -s -f -m *computername -t 10 -c "test"

replace * with \\ (whenever I do it it makes it a hyperlink).

 

It would shutdown a remote computer called (in this example) computername.

 

However this doesn't work, the computer I'm trying to shutdown is called Oliver and here's what happens everytime I try to use run the command (below), my question is why?

 

The computer oliver was active and all and a ping to that computer works fine, the network path certainly exists!

shutdown.JPG

Link to comment
Share on other sites

This is just a WAG, but have you looked at security policy issues? I believe there may have been a change in policy in a recent patch which specifically prohibited remote shutdown/reboot by default. Google on "remote shutdown" and "remote reboot" and the drill down (sub-search) with the keyword "policy", and focus on recent results.

Link to comment
Share on other sites

echo

echo Restarting the pc in 10 seconds.....

shutdown.exe -r -f -t 10 -c "Windows XP will now restart in 10 seconds"

 

Just out of interest, what does the first 'echo' do? The one that iv enboldened?

 

Its not the cause of your problems, im just curiouse as to what its for.

Link to comment
Share on other sites

The MS website mentions nothing (and I found a page where it should) about a policy change, if anything XP SP2 might do something but I can't find any documentation about it.

 

So I got bored of searching but did find that if you go to your desktop and right click > new > new shortcut and type in:

shutdown.exe -i

and then follow on screen instrcutions!

 

The problem is that in the computer-select box (when you open the shortcut you just made) I cannot see any computers, and when I chose to browse I get the error message saying "The Directory Service is currently unavailable", I'm working on that.

 

Also I knew already that I must be admin over any computer I wish to shutdown... how do I know if I'm an admin over another computer?

I've just got a simple 3 computers to a router, there is no admin as such.

Link to comment
Share on other sites

I think the first echo is simply to move the cursor down (ie newline)

wouldnt that have to be echo. <--note the full stop

 

i think echo just returns the status of echo (ie, either prints 'echo is on' or 'echo is off' )

Link to comment
Share on other sites

i think echo just returns the status of echo (ie, either prints 'echo is on' or 'echo is off' )
By typing echo by itself (no dot) it will make echo on, even if it's already on it turns it on, if it's off it turns it on, it always turns it on!
Link to comment
Share on other sites

I think the prob here is that I'm not admin over the other PCs.

 

It's a simple 3computer-->router equal access network.

 

So I guess the question is how can I make one of the computers into an admin computer?

 

(Two XP & one 98)

Link to comment
Share on other sites

Sounds like you're on the right track. Whether or not you're an admin is determined by your login credentials. If you aren't logging in during the execution of the script, then your credentials are carried over from when you logged into the local machine. That would presumably not be an admin on the remote computer (the one you're trying to shut down). You can either create an account on the remote computer that's identical to the local computer, or you can manually log in to the remote computer.

 

You should be able to do a run-as in that script, and have it always execute as Administrator. I.E. something like "runas <login parameters> shutdown.exe" etc. Been a while since I did a script like that, so you may need to run some searches for the exact syntax.

 

If that doesn't work, you can probably right-click on the script in Windows Explorer, get properties, and set the run-as parameters there.

Link to comment
Share on other sites

You can either create an account on the remote computer that's identical to the local computer
I don't follow. Do you mean the account that you use log onto when winXP loads? Because all computers have a default account assigned which is an admin of the computer. Consequently both oliver and I are running admin accounts, should I degrade oliver to a limited account?

 

Also whenever and however I run this file it always says that it cannot find Oliver, not that I don't have the correct priveleges or permission, does this mean that possibly we are on the track?

Link to comment
Share on other sites

Can you find "Oliver" through Windows Explorer, or by other means? For example, if you open the Run command and type \\Oliver, what happens? If it says that it can't find Oliver, then you have an infrastructure problem -- fix your network. But it sounded like you were able to access the computer remotely by other means earlier in this thread.

 

Whenever you do anything in Windows, you do it "as" someone. That someone is your login username. There is no way around this. When a system loads "straight to the desktop", it's not actually bypassing login, it's remembering your username and password from before. The easiest way to see whom you are logged in as is by clicking on the start menu. Whatever name you see listed there is your username.

 

If you attempt to do something across the network, you're carrying your "credentials" (username and password) with you. Either they'll work, or they'll fail and the system will prompt you for appropriate credentials for that system. (This happens, for example, if you try to access a share. It's not immediately obvious, but the reason why it's asking you for credentials is because your current ones, for your local system, have failed to authenticate you.)

 

So if your username does not exist on the remote system (the one you're trying to shut down), then it needs to be given appropriate credentials. In a script it can't prompt you for anything, because, well, it's a script. You have to build that funtionality into your script, or set parameters outside the script (the run-as settings on the Properties sheet for the script file) in order to make that happen.

Link to comment
Share on other sites

Put another way, walk over to the "remote" system and get the password for the "Administrator" account.

 

I just checked, and my memory is bad -- you can't run-as a .bat file, alas. I guess that's only for .exe. So you're stuck with the command line.

 

If you type "runas" on the command line, it'll show you the syntax, but it's basically like this:

 

runas /user:Pangloss myscript.bat

 

It'll prompt you for the password for "Pangloss". I'm pretty sure you can include the password in a batch file somehow, but I don't recall at the moment. You'll have to look that up.

Link to comment
Share on other sites

Yeah I can access Oliver through run or network places, I can see the folders on c:\ but otherwise it's not shared, so I cannot go to c:\program files although I can see the folder program files because I can see what's on the C drive.

 

Either they'll work, or they'll fail and the system will prompt you for appropriate credentials for that system.

They don't work and they don't ask for more. Maybe this is due to the admin vs admin situation (because when you first load winXP it needs to create an account which is auto an admin account). So if I degrade Oliver to a limited access account will that work?

 

So if your username does not exist on the remote system (the one you're trying to shut down), then it needs to be given appropriate credentials.
Same question as above, would keeping myself as admin and degrading oliver to limited access be counted as appropriate credentials?
Link to comment
Share on other sites

Whoa, you don't need to degrade Oliver to limited access, and I don't think that can address your problem at all. I'm not sure where you're getting that idea from, but it seems totally out in left field to me. If I understand what you're telling me, your problem can only be solved by using appropriate credentials while trying to control Oliver. You've already established that the Administrator account has the authority to do what you want it to do, right? The only problem is establishing that you are the Administrator when you connect remotely. Oliver doesn't think that you are an administrator. You need to convince him that you are. There's really only one answer here -- you have to give him your credentials, one way or another.

 

I think you may have stopped reading my messages at the point where I said that it would prompt you for credentials, not realizing that I was talking about shares at that point, not batch/script files. Batch/scripts won't stop and prompt you -- I agree. You have to provide that information in the script, or via a calling script/procedure/app that first establishes credentials and then calls your script.

 

I've given you some suggestions above as to how you might approach that problem, but you're going to have to look it up for the syntax of how to login via script.

 

(I think it might be /username:password, but again, you need to look it up.)

 

 

Maybe this is due to the admin vs admin situation (because when you first load winXP it needs to create an account which is auto an admin account).

 

I'm not sure if you're visualizing the credentials metaphor correctly, so let me flesh it out a little. Forgive me if you already know this.

 

First, a minor correction: When you first load XP it drops the first account that you create into the "Administrators" (note the "S") group. This is not the same thing as making it the Administrator. There is, also, an "Administrator" account, and you gave it a password when you installed Windows XP. You can see it in Computer Management => Users and Groups (and I believe you can change its password there, if you can't remember it, or if you want to match it to the Administrator password on Oliver -- just right-click on it and select "Set Password").

 

Bear in mind that just because you have an account in the administrator's group on the local system doesn't mean that it's in the administrator's group on Oliver. Administrator privileges on one system do not grant administrator privileges on another system (unless you're in a domain and we're talking about domain administrators, but that's a whole other ballgame).

 

Just to try to spell that out a little more clearly:

 

All Local Computer Accounts

Pangloss

Administrator

 

All Oliver Accts

Jonathan

Administrator

 

In this configuration, if I log in to the local computer as "Pangloss", I cannot shut down Oliver, because Pangloss is not an administrator for Oliver. He is only an administrator for the local system. There is no "admin to admin" conflict, mind you -- I simply am not an admin on Oliver at all.

 

On the other hand, if I log into the local system as "Administrator", I should have the authority to shut down Oliver IFF (IF AND ONLY IF) the password for the Administrator account on Oliver is exactly the same password used for the Administrator account on the local system. If they are not the same, then I cannot shut down Oliver (unless, of course, I somehow present the correct credentials along with my shutdown script).

 

Alternatively, you can create a "Pangloss" account on Oliver, drop it into the Administrator's group, and that may allow you to shut down Oliver without having to present credentials at all. I'm not certain that will work, however -- you may still need to present credentials in the batch file. But it's worth a shot.

 

I hope this is some help to you. :)

Link to comment
Share on other sites

I want you to know that I am reading all of your posts thorougly and just because I don't fully understand it doesn't mean I aint learning!

 

About the admin account password... both admin for mine and his computers are blank, just nothing.

 

I'll try it tomorrow (its 11:15pm here), you can only accses admin account from safe mode so I'll copy over the .bat file to admin desktop and I'll do it tomorrow and will post here.

Link to comment
Share on other sites

if I log into the local system as "Administrator", I should have the authority to shut down Oliver IFF (IF AND ONLY IF) the password for the Administrator account on Oliver is exactly the same password used for the Administrator account on the local system.

The passwords for both Administrator accounts (which you can only access in safe mode and cannot see in User Accounts unless in safe mode also) is blank, password-less.

 

So I booted to safe mode with networking, logged onto Admin and still it comes up with the same 'Network path not found' message.

 

If I use net view it comes up with oliver, if I enter it into run it works, ping work, we can share docs to "Shared Documents" only.

 

After the result of the admin thingy, is it possible "The network path could not be found" should be taken more literally and it isn't to do with admin rights?

Link to comment
Share on other sites

which you can only access in safe mode and cannot see in User Accounts unless in safe mode also

 

Are you sure? You should be able to see the Administrator account in the Local Users and Groups applet if you're logged in with that initial account (the one that was automatically dropped into the administrators group). It works for me.

 

You might want to go to Computer Management (right-click on My Computer in the Start menu and click on Manage), then go to Local Users and Groups, go to Users, and see if the Administrator account is listed there.

 

 

If I use net view it comes up with oliver, if I enter it into run it works, ping work, we can share docs to "Shared Documents" only.

 

After the result of the admin thingy, is it possible "The network path could not be found" should be taken more literally and it isn't to do with admin rights?

 

Shared Documents is not normally visible across the network. It's actually for sharing documents between different users on the same computer. Did you share it on purpose? Nothing wrong with that, it's just a little unusual. Normally you create folders specific folders for that purpose, and share them. I'm not criticizing your methods here, just pointing out all irregularities because I'm still pretty confused about the problem is.

 

Just to clarify, is this what you're telling me that you are doing?

 

0) This is NOT while in Safe Mode w/networking -- just boot normally. I don't know why you did that, but it isn't necessary. Again, nothing about any of these accounts should ever have anything to do with the boot state of the computer.

 

1) You log in to the local system as Administrator (not the first-user account you mentioned earlier, which was also an administrator account because it was dropped into the administrator's group automatically -- you're saying now that you are not using that account at the moment, right?).

 

2) You are able to access shares on the remote system and you are not prompted for a password when you do so. (Which would make sense, because both systems have an account on them which is called "Administrator", with the same (no) password.)

 

3) You are unable to execute your script in that configuration.

 

Is that right?

Link to comment
Share on other sites

You might want to go to Computer Management (right-click on My Computer in the Start menu and click on Manage), then go to Local Users and Groups, go to Users, and see if the Administrator account is listed there.
Are you using XP Pro? I'm using XP Home and am quite familiar the Computer Management and there's no Local Users/groups (see attachment).

 

Administrator is not in User Accounts (see attachment)

 

Administrator, the account, cannot be seen normally, only in safe mode does Administrator appear, this is meant to happen in winXP Home. I cannot log into admin unless I am in safe mode, so this is what I did.

 

I dunno why Shared docs is shared over the network and nothing else is... It's not me who decides what happens on his computer (well, except when it shuts down, I hope!) Maybe I did shared it once, if I did which I don't think I did then I can't remember, but I doubt I did that.

 

Everytime I execute the script, under any circumstances it says "Unable to find network path".

accounts.JPG

comp manage.JPG

Link to comment
Share on other sites

Ah, now the picture begins to become clearer. XP Home is very different in a number of respects in this area. Is Oliver also running XP Home?

 

I don't know if you will be able to do this. I've simply never done any remote script execution in XP Home. It may just be something hard-coded not to work. They put in a lot of really funny restrictions that were specifically designed to stop people from managing XP Home boxes across a network, which is what we're talking about here, so it wouldn't surprise me at all if it were just not allowed.

 

Have you tried putting the /user:Administrator switch into the execution string yet? It seems like a logical thing to try.

 

Beyond that, I'm afraid I'm at a loss. You're going to have to hit the Microsoft newsgroups for this one. Do you know where to go for those?

 

Sorry guy.

Link to comment
Share on other sites

Ah, now the picture begins to become clearer. XP Home is very different in a number of respects in this area. Is Oliver also running XP Home?
Oliver is also on winXP Home... I knew about the only difference between Home and Pro is the networking facilities, shame, I could get Pro, but, um, it wouldn't technically be legal and I don't like the idea of an illegal OS.

 

Have you tried putting the /user:Administrator switch into the execution string yet? It seems like a logical thing to try.
Not yet, will do soon.

 

Beyond that, I'm afraid I'm at a loss. You're going to have to hit the Microsoft newsgroups for this one. Do you know where to go for those?

http://www.google.co.uk/search?hl=en&q=microsoft+newsgroups&meta=

Something like that? Any you would suggest?

 

Sorry guy.

No prob. you've been great and ive learned a lot, thanks!

Link to comment
Share on other sites

Have you tried putting the /user:Administrator switch into the execution string yet? It seems like a logical thing to try.
I'm trying it now and it's not working. I assume you want me to put it into the .bat file, I wasn't quite sure where so I tried it by itself and infront of the shutdown command, neither worked... is that definately the correct syntax?

 

I've never used this command before, it's logical what it is supposed to do but I've never used it so am not sure how to use it properly. I'm using this script:

 

echo

echo Restarting the pc in 10 seconds.....

shutdown.exe -s -m \\oliver -t 5 -c "JMM testing" -f

pause

 

(with the pause at the end so I can see what error message I am getting,) if you wanna add the /user thingy into where it should be that'd be great.

Link to comment
Share on other sites

Well as I said above, you're going to have to look it up. But this is how I think it would work:

 

Go to the command line and type this:

 

shutdown.bat /user:Administrator

 

(assuming that "shutdown.bat" is the name of your script)

 

If that works, it ought to also be possible to incorporate that user switch into the batch file somehow, but you're going to have to look that one up. Perhaps something like this:

 

shutdown.exe -s -m /user:Administrator \\oliver -t 5 -c "JMM testing" -f

 

But that's just a wild guess.

 

I'm sorry I haven't been able to give you anything more definitive on this, but as I say, it's been a while since I've done anything along these lines. Good luck! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.