Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBS to run DOS commands

Status
Not open for further replies.

Hellooooooooo

Technical User
Oct 21, 2005
66
GB
Hello everyone.

So I have small problem. I have 2 users that have a need to run DOS commands, however our lockdowns don't allow this to happen.

The 1st user needs to ping an IP address before he can carry out a job. Ive cobbled together the following from the web.

Option Explicit
Dim Shell, strCommand, strHost, strUserIn, ReturnCode
Dim Message, result
Dim Title, Text1
'Message Box Variables.
Message = "Please enter the address you wish to ping"
Title = "PingPong, K.I.S.S."
Text1 = "User abort"
'Text2 = "You entered:" & vbCrLf
result = InputBox(Message, Title, "127.0.0.1", 8000, 6000)
'Evaluate the user input.
If result = "" Then ' Canceled by the user
WScript.Echo Text1
Else
'WScript.Echo Text2 & result
strHost = vbCrLf
'Create shell object
Set Shell = wscript.createObject("wscript.shell")
'What to run in command line
strCommand = "ping -n 1 -w 10 " & strHost
'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)
'0 = pingable, 1 = no response
If ReturnCode = 0 Then
wscript.echo strHost & " pingable"
Else
wscript.echo strHost & " not pingable"
'End If
End If
End If

Running this should ask for the address to be pinged then nreturn a popup if its pingable. I can get it to take an IP address, but it wont return a result.

The 2nd user is a nightmare. He needs to use DOS to run the DIR command with a few switches and return the result to a text file. This VBS script should take his command as he types it and complete it for him.

Any pointers??? this is causing me a nightmare as they are asking for full admin rights to do this. By the way this is all running on NT4 ang Win2k boxes.

Any help would be grand.

Thanks
 
1st question that needs to be answered: will your lockdowns allow a script to run DOS commands?
 
Hello jges.

Well the lockdowns have everything locked down, ish. I can get VBS script to run for a user. It's a slight flaw in the lockdown, but it will help me to get these 2 users sorted out.
 
See: faq329-3330

strongm had an excellent routine to ping computers using wmi, but I can't seem to find it right now. If you look hard enough with the search functionality it may turn up for you.

This VBS script should take his command as he types it and complete it for him.
Pure VBScript has very limited GUI capabilities, this request will be tough. You might consider a programming tool such as Visual Basic (there is a free basic version available from MS).
 
Thanks HughLerwill, that's the one I was thinking of. It shows up again here (in the VBScript forum): thread222-1611646

Also there is a FAQ that may be useful here: faq329-6527
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top