We have a PC bank here and we need a new way to reset them remotely from another machine. Is this possible in VB?
Printable View
We have a PC bank here and we need a new way to reset them remotely from another machine. Is this possible in VB?
The new version of RAS does it nicely. It's in your NT Backoffice stuff. Study up on it before you install it, because it can really wipe out a network if not set up correctly.
Check out InitiateSystemShutdown API.
You can shutdown remote computer (WinNT only), like this:
Subsitute PCName with the name of the computer you want to shutdown.Code:Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, lpMessage As String, dwTimeout As Long, bForceAppsClosed As Boolean, bRebootAfterShutdown As Boolean) As Boolean
Private Sub Command1_Click()
Dim lRet
lRet = InitiateSystemShutdown("PCName", "Shutdown...", 0, True, False)
End Sub
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
Thanks, I tried the API call but no matter what timeout i give it it pops up on the targeted pc with a dialog saying the computer will be shut down in 14 days and the comment is giberish characters. Any ideas why?
Figured it out, silly thing to overlook. The other variables were just missing ByVal, once they had it the call worked perfectly. Thank you
How could you shut down multiple machines? Can you separate PCNames with commas??
Simon
All i do to reset all 120 pc's is i have a listbox with all the pc's names in it (so we can exclude any that are acting up) and i do a loop that reads the names off the listbox and inserts it for lpmachinename. It's easier here since all our machines are named in numberical order (pc001, pc002, ect). The only problem i've had is I'm not sre how to get a heartbeat from the PC to make sure it can respond to the restart command. As it is if the pc is not reachable it hangs the program untilt he API call times out. this tends to cause other problems.
can't it just PING the machine?
------------------
Rapmaster
One side problem I've more or less gotten around is when a pc writes a response file (more on that below) and my program tries to read and delete it it sometimes tries to delete while the file is still being written. I have a loop with an aritrary number to delay the process a few ticks but would like to find a better way. Is there a way to test if the file can be deleted? Right now i'm just going to say on error wait and try it again a bit later.
In reguards to the last post, I could do it that way but it's messier, that spams out 120 windows at once all of which would dump the ping data into a file which would have to be opened and read in order to check if the ping failed. This would work since any system my program runs on in here has a minimum of 2 processors but i've come up with a diffrent way.
In order to see if the pc's rebooted I made a routine that copies out a cmd file to the startup directory of all the pc's (this works because that all login as the same user). The cmd's run when the machine reboots and autologs in, when it runs it copies a empty file to one of my programs subdirectories using the computer name as the filename, then the cmd deletes itself. Meanwhile my reset program has gone into a loop where every few seconds it checks for files in the directory, checks them against the pc names and when it finds one marks it off and deletes the file. This continues until all the expected pc's are marked off or 30 seconds has passed since the last login (needed because ocasinaly for whatever reason a pc reboots and does not send a reply back). I'm going to alter the copy routine to know if it suceeded in the copy and if it doesn't to automaticaly move the pc that didn't respond to the exclude list so nothing tries to run on it for the rest of the test.
This may seem all needlessly complex but we're running a lab where we test Terminal Server (look it up onthe Wimcrosoft homepage under NT Terminal Server or win2k Advanced Server or Datacenter) and due to the requirements we need a completely server based application that provides feeback and generaly simplifies the testing procedure. This routine is simple compared to what i had to rig up to actually get the script playback to work correctly. If anyone has some suggestions please let me know.
Sorry to sound really dumb, but looping is quite new to me!
I have a .txt file with machine names listed on each line.
EG. (art-14.txt)
ART-14-1
ART-14-2
ART-14-3
ART-14-4
etc
I need a little bit of code that will load the text file, read off each line, and using some sort of loop, insert it as the PCName.
I've been playing for a bit but keep hitting the preverbial wall!
Hope someone can help! Thanks
Simon