Solved

InitiateSystemShutdown on Windows XP

Posted on 2004-08-10
19
748 Views
Last Modified: 2012-06-27
i cant seem to get InitiateSystemShutdown to shutdown a remote Windows XP machine (XP Home)... i get this error...

53 (ERROR_BAD_NETPATH) The network path was not found.  

but the path is right... it also seems that i cant used SHUTDOWN.EXE to shutdown that machine either.  anyone know what the problem is??
0
Comment
Question by:RobK6364
  • 10
  • 8
19 Comments
 
LVL 7

Expert Comment

by:_agj_
Comment Utility
i dont remember the exact syntax..but u cud do something like:

rundll32.exe "user32.dll", "ShutDownWindows"
0
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
Comment Utility
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
i'm very interested in the idea of WMI... it adds some additional functionality, but it still isn't working on my Windows XP machine.  it's returning error 5 (ERROR_ACCESS_DENIED)... but i am Admin on local and remote machines...

and according to the article, WMI is always included in Win2k and WinXP.  worked great on my Win2k machine, but access denied on WinXP.  any idea why?
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
actually error 5 (access denied) is what i get when i click the computer in the list which calls GetWorkstationInfo.  The error message when i try to shutdown the WinXP machine is error 91 - Object or With Variable Not Set.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Sorry, I can't explain it not working on XP.  I doubt if it's WMI not being on the machine.  More likely a permissions issue.  Here is Microsoft's documentation of the Win32Shutdown procedure:
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32shutdown_method_in_class_win32_operatingsystem.asp)

I ran the code from the second of the two links I gave in my initial post and successfully shut down two different XP machines in my domain.  I'm an administrator as you are.  The code from the first link is a subset of the code from the second link, so it should work too, although I haven't tried it.  Which did you try?
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
i clicked the "full code available here" link on the from the first page you posted.

if you were able to shutdown XP... then i'm sure i'll figure out the permission problem.  just one more question, er 2 actually... first were the XP machines XP Home edition or Pro edition?  and second... you mentioned "your domain" by that i assume you mean an actual domain and not a workgroup?

cause i am actually testing on a small home network with 2 WinXP Home computers and a Win2000 Pro (on my laptop)... and all the computers are actually in a workgroup and not a domain; however i noticed that in that example program "domain" can be a workgroup and it will work.  that's why i ask what you tested on?
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Both of the machines I tested against are XP Pro.  Yes, I meant an actual domain, an AD domain in my case, and not a workgroup.  When I get home tonight I can test this on my home network which is a workgroup and has some XP Home PCs.  I'll let you know how that works out.
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
ok great, thanks :)
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
I just finished testing and it worked.  Using the RemoteReboot app I was able to shut down an XP Home Edition PC on my home peer-to-peer network.  I initiated the shutdown from a desktop PC running Windows 2000.  The account I was logged in under on the 2000 machine is a member of the Administrators group on the XP Home machine.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:RobK6364
Comment Utility
ok, well i haven't had much time to work on this... but if you say you got it workin, then i'm sure i'll figure it out.  Thanks for helping. : )
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.  If you run into a problem when you get back to working on this, post a message here and I'll be glad to help out.
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
actually there is one more thing i was wondering if ya could check for me...

there is a line in that demo... "Debug.Print p_objComputer.Name"
i was wondering if you could tell me what p_objComputer.Name is set to when you reboot your Windows XP machine.

my Windows 2000 machine returns this...
Microsoft Windows 2000 Professional|C:\WINDOWS|\Device\Harddisk0\Partition1

and since the error i'm getting is at this line..
Set p_colComputers = p_objWbemRoot.ExecQuery("Select * from Win32_OperatingSystem")

because it's apparently not returning the collection; therefore i never get into the loop when i try a Windows XP machine.  so i'm wondering if there is a way i might skip the collection and create the string manually as the demo's author says could be done but would require extra code.
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
well... i've come to the conclusion that i'm not really authenticated as Admin on the remote machine.  This is kind of embarassing, but if you are still around Blue Devil...

When i setup my home network... just for file sharing purposes... i created the shared folders and I created a local user account on each machine... then when i would access a remote machine... it was my understanding that the remote machine would try to authenticate me there based on the username i was logged into on my local machine (and if invalid, would popup box to ask for another user/pass)...

and since my "Admin" account was created on each PC with the same password, i figured that was why i was getting in to my remote shared folders with no problem.

well today i tried creating a non-admin account on the local pc... and to my surprise, i was still able to view the shared folders on the remote pc that did not have this new non-admin account at all.  i could even delete files.

when administrating Windows2000 Pro with Group Permission and such... i understand (i think, lol)... but WinXP Home's permission dont use groups, right?  there is just "administrator" or "limited user"... and when sharing folders you cannot attach groups to the folders... you just say if "network users can modify my files"

anyway, so i guess i'm an idiot, lol.  can you explain how you set up your network so that you were authenticated as Admin on your remote WinXP Home machine?



0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Well, apparently it's me who's the idiot.  Doh!  When I ran my test and reported back that the process had worked on XP Home I was wrong.  Wrong in that the machines I tested against have XP Pro, not XP Home.  I didn't discover that until I went to collect the information for p_objComputer.Name that you asked for on the 12th.  I would have sworn that both of the machines I tested against had XP Home.  I should have checked that, but I was so sure.  Either I upgraded them at some point or I'm just losing my mind altogether.  Maybe I need to start taking Ginka Biloba.  I do have another PC that does have XP Home, I checked the screen when it boots, and the remote shutdown does not work there.  I did some additional research and found out why.  It seems that Microsoft has disabled remote WMI access in XP Home.  This link (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/connecting_between_different_operating_systems.asp) will take you to article that spells that out.  Look about 2/3's of the way down the page under "Failing to connect?".  So, the WMI approach isn't going to work for you.  I'm searching for a suitable alternative.  

Sorry about that!
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
hmm... too bad.  i've been lookin into the possibilty of using CreateService to create a service on the remote PC's... then in that service i can use ExitWindows/ExitWindowsEx locally in the service.

http://msdn.microsoft.com/library/?url=/library/en-us/dllproc/base/createservice.asp

but i'm getting error 87 (invalid parameter) returned on the CreateService call...
'-----------------------------------------
hSCM = OpenSCManager("\\REMOTEPC", vbNullString, SC_MANAGER_CREATE_SERVICE)

lngResult = CreateService(hSCM, "MyTestService", "MyTestService", SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, "C:\Test\ServTest.exe", vbNullString, vbNullString, vbNullString, vbNullString, vbNullString)

0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
oh... and OpenSCManager is returning a valid handle
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
That sounds like a good solution.  I've never written a service using this approach, so I'm afraid I can't be of help with the problem you've run into.  I write all my services using the ServiceMill control (http://www.activeplus.com/us/products/smillcontrol/).  It works great, but isn't free.  If you'd like to try a free control, then you might have a look at NTSVC.OCX (http://www.freevbcode.com/ShowCode.Asp?ID=4317).  You could also use SRVANY (http://www.vbwire.com/advanced/howto/service.asp) which allows any program to run as a service.
0
 
LVL 1

Author Comment

by:RobK6364
Comment Utility
thanks for all your help... in case you are interested...

i figured out how to call CreateService correctly.  And i've been doing some reading and from my understanding when you have Simple File Sharing enabled on the remote machine... all user for whatever reasion (file sharing, createservice call, etc) are authenticated as Guest... which is why i get access denied on WMI, CreateService, and even InitiateSystemShutdown.

furthermore, since Windows XP Home Edition cannot disable Simple File Sharing... you cannot make any of these calls to Home Edition. :(

and also if you are on XP Pro and disable Simple File Sharing, you still have to make sure you have a password on the account you are trying to use.  so no passwordless admin access accross the network.

so i figure i can just install my service one time on Home Edition machines... and i can do XP Pro, 2000 Pro, etc remotely with CreateService.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.  Yes, that is interesting.  I knew there was some reason I didn't like XP Home.  Sounds like you've got a viable solution.  Let me know how it goes.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now