Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › VBS won't kill CMD.exe if ran via PSEXEC
New Posts  All Forums:Forum Nav:

VBS won't kill CMD.exe if ran via PSEXEC

post #1 of 3
Thread Starter 
The issue I have is that I required to test open ports on a remote server and relay all results back to the central server.

To do this I wrote a batch file which opens cmd on the the remote server and executes some commands
Code:
Set cloner = CreateObject("WScript.Shell")
        cloner.run"cmd"

        WScript.Sleep 500
        cloner.SendKeys"telnet " & server & " " & port

        cloner.SendKeys("{Enter}")
        
        Set cloner2 = CreateObject("WScript.Shell")
        cloner.run"cmd"
        
        WScript.Sleep 500
        cloner.SendKeys"netstat -an > C:\Temp\PortCheck\connected.txt"
        
        cloner.SendKeys("{Enter}")
        WScript.Sleep 5000

        cloner.SendKeys"exit"
        cloner.SendKeys("{Enter}")
        WScript.Sleep 1000
        
        cloner2.SendKeys"exit"
        cloner.SendKeys("{Enter}")

If I run the VBS file via command prompt or just clicking it on the locally, the script runs, completes and closes the command prompt windows.

However, as soon as I execute it from a remote server using PSEXEC
Code:
"C:\psexec.exe" \\%~1 -s cscript "C:\Temp\PortCheck\file.vbs"

The VBS file executes successfully and does everything it needs. The only issue is that it does not kill the command prompt windows on the remote server like it does if its ran locally. By using psexec, it does not give anything to view on the remote server (this is what I want) however could this be something to do with why the cmd's don't close?

Does anyone know why or how I can resolve this?
Killing all cmd.exe's is not an option as these servers are used for other purposes and killing cmd.exe could cause a few problems
    
CPUMotherboardGraphicsRAM
Intel i7-4850HQ  Yes GT 750M 16GB Corsair 
Hard DriveHard DriveOSMonitor
512GB SSD 1TB Buffalo Drivestation OSX Mavericks 15" 2880 x 1800 IPS 
MouseOther
Magic Mouse Mobee Magic Charger 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel i7-4850HQ  Yes GT 750M 16GB Corsair 
Hard DriveHard DriveOSMonitor
512GB SSD 1TB Buffalo Drivestation OSX Mavericks 15" 2880 x 1800 IPS 
MouseOther
Magic Mouse Mobee Magic Charger 
  hide details  
Reply
post #2 of 3
Thread Starter 
Anyone?
    
CPUMotherboardGraphicsRAM
Intel i7-4850HQ  Yes GT 750M 16GB Corsair 
Hard DriveHard DriveOSMonitor
512GB SSD 1TB Buffalo Drivestation OSX Mavericks 15" 2880 x 1800 IPS 
MouseOther
Magic Mouse Mobee Magic Charger 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel i7-4850HQ  Yes GT 750M 16GB Corsair 
Hard DriveHard DriveOSMonitor
512GB SSD 1TB Buffalo Drivestation OSX Mavericks 15" 2880 x 1800 IPS 
MouseOther
Magic Mouse Mobee Magic Charger 
  hide details  
Reply
post #3 of 3
Why not just run it immediately instead of doing the goofy sendkeys stuff? Does it close then?

Set cloner = CreateObject("WScript.Shell")
cloner.run"ping google.com"


If that's no good, you can use the methods here to create a process and preserve its process ID. That way if it doesn't close on its own, you can do it yourself after sleeping for a certain period of time.
Edited by Desidero - 1/19/12 at 5:16pm
The New Guy
(16 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0@3.0GHz GA-P35-DS3L EVGA 8800GT Superclocked 4GB Corsair XMS2 DDR2 800 
Hard DriveHard DriveOptical DriveOS
Seagate 320GB 7200RPM Western Digital Caviar Black Lite-on DVD burner Windows 7 Professional x64 
MonitorKeyboardPowerCase
Samsung 225BW Filco Majestouch Ninja (full keyboard w/browns) Cooler Master Xtreme 650 Antec 900 
MouseAudioAudio
Logitech MX518 Denon AHD-2000 Sennheiser HD595 
  hide details  
Reply
The New Guy
(16 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0@3.0GHz GA-P35-DS3L EVGA 8800GT Superclocked 4GB Corsair XMS2 DDR2 800 
Hard DriveHard DriveOptical DriveOS
Seagate 320GB 7200RPM Western Digital Caviar Black Lite-on DVD burner Windows 7 Professional x64 
MonitorKeyboardPowerCase
Samsung 225BW Filco Majestouch Ninja (full keyboard w/browns) Cooler Master Xtreme 650 Antec 900 
MouseAudioAudio
Logitech MX518 Denon AHD-2000 Sennheiser HD595 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › VBS won't kill CMD.exe if ran via PSEXEC