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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call External VBscript

Status
Not open for further replies.

willxfox

IS-IT--Management
Jan 3, 2012
5
US
I have a VBscript located on a remote computer. I want to setup an HTML page to call the specific VBscript and run locally from where it resides. I have the basic setup done but when trying to run the script via the HTML webpage it tries to run the script from the computer where the webpage is opened. I want the script to run on the remote computer where it resides. Here is what I have so far in my index.html

<html>
<head>
<title>ON call Script</title>
</head>
<script language="vbscript">

Public Sub RunScript()
Set objWSH = CreateObject("WScript.Shell")
strCMD = "cscript.exe c:\Scripts\AA.vbs"
objWSH.Run(strCMD)

End Sub

</script>
<body>

<br>
<INPUT TYPE=BUTTON OnClick="RunScript" VALUE="RUN">This is some text<br>

<br>
</body>
</html>
 
browsers typically don't allow local scripts to run when called from a webpage. Check the browser's security settings. Also, rename the .html file .hta. IE won't care then.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I changed to page to .hta and now it only displays the text when I click on the file from the apache webpage. Again, when it was in .html it will run the vbscript but from my local PC and not run locally on the remote PC.
 
you want to execute cscript.exe then on the remote machine? i think this is really what you are saying?

strCMD = psexec.exe \\remote_machine_name cscript.exe c:\...etc

might be one way of doing it?

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
oh, sorry. I misunderstood.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Can psexec be run from a HTML webpage?
 
i presume so, same way using WshShell.Run, providing the client running the html page has the binary locally i guess

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Hi ! Try this Tool Created by Stuart Barrett PSExec Command Builder.hta
Description :
Allows a user to build and perform PSExec commands upon a machine using a GUI form and also offers the unique ability to save / open commands.
Copy and Paste this code below and save it with a .HTA extension
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="description" content="Created by Stuart Barrett">
<meta name="description" content="Last Update: 24/05/11">

<script language="VBScript">
	intLeft = window.screenLeft
	intTop = window.screenTop
	window.moveTo -2000,-2000
	window.ResizeTo 1,1
</script>

<title>PSExec Command Builder</title>

<HTA:APPLICATION
	APPLICATIONNAME="PSExecCommandBuilder"
	ID="objPSExecCommandBuilder" 
	VERSION="1.5"
	BORDER="dialog"
	APPLICATIONNAME="PSExecCommandBuilder" 
	SCROLL="no" 
	MAXIMIZEBUTTON="no"
	SINGLEINSTANCE="yes" 
	CONTEXTMENU="no"
	WINDOWSTATE="normal"/> 

<style type="text/css">

body {
	font-size: 0.9em;
	cursor: default;
	font-family: calibri, "Times New Roman", helvetica, sans-serif;
	background-color: #eeeeee;
}
.hidden {
	display: none;
	visibility: hidden;
}
input {
	font-family: verdana; "Times New Roman", calibri, helvetica, sans-serif;
}
input.button {
	color: black;
	cursor: hand;
	background-color: white;
	border: #000033 2px solid;
	height: 25px;
}
input.text {
	border: #000033 1px solid;
	height: 23px;
	padding-left: 3px;
}
input.btnhov { 
	border-color: #000033;
	background-color: #cccccc;
}
input.disabled { 
	background-color: #eeeeee;
	border-color: #888888;
	cursor: default;
}
</style>
	
</head>

<script language="VBScript">

'#==============================================================================
'#==============================================================================
'#  SCRIPT.........:	PSExecCommandBuilder.hta
'#  AUTHOR.........:	Stuart Barrett
'#  VERSION........:	1.5
'#  CREATED........:	03/11/10
'#  LICENSE........:	Freeware
'#  REQUIREMENTS...:  
'#
'#  DESCRIPTION....:	Allows a user to build and perform PSExec commands 
'#						upon a machine using a form and also offers the unique
'#						ability to save / open commands
'#
'#  NOTES..........:	Taken from my PC Management Utility, check it out:
'#	[URL unfurl="true"]http://community.spiceworks.com/scripts/show/585-computer-management-utility[/URL]
'# 
'#  CUSTOMIZE......:  
'#==============================================================================
'#  REVISED BY.....:  
'#  EMAIL..........:  
'#  REVISION DATE..:  
'#  REVISION NOTES.:
'#
'#==============================================================================
'#==============================================================================

	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objShell = CreateObject("Wscript.Shell")

	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	RunPSExecCommands()
    '#	PURPOSE........:	Allows a user to build and perform PSExec commands 
	'#						upon a machine using a form and also offers the 
	'#						ability to save / open commands
    '#	ARGUMENTS......:	
    '#	EXAMPLE........:	
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub RunPSExecCommand()
		On Error Resume Next
		booPSExecInPath = False
		
		If IsNull(txtComputerName.Value) OR txtComputerName.Value = "" OR txtComputerName.Value = "." Then
			txtComputerName.Value = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
		End If
		txtComputerName.Value = UCase(txtComputerName.Value)
		strPC = txtComputerName.Value
		
		If NOT Reachable(strPC) Then
			ShowDiv(NotFoundArea)
			Exit Sub
		End If
		
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPC & "\root\cimv2")
		Set colComputer = objWMIService.ExecQuery _
			("Select * from Win32_ComputerSystem")
	
		For Each objItem In colComputer
			strLoggedOn = objItem.UserName
			If IsNull(strLoggedOn) Then strLoggedOn = "none"
		Next
		
		LoggedOnSpan.InnerHTML = Trim(strLoggedOn)
		
		strPath = objShell.ExpandEnvironmentStrings("%path%")
		arrPaths = Split(strPath, ";")
		For i = 0 To UBound(arrPaths)
			strPathFolder = arrPaths(i) & "\"
			strPathFolder = Replace(strPathFolder, "\\", "\")
			strPathFolder = Replace(LCase(strPathFolder), "%systemroot%", _
			objShell.ExpandEnvironmentStrings("%systemroot%"))
			If objFSO.FileExists(strPathFolder & "psexec.exe") Then 
				booPSExecInPath = True
				strPSExecLocation = strPathFolder & "psexec.exe"
			End If
		Next

		If booPSExecInPath = False Then
			If UBound(arrPaths) < 21 Then
				For i = 0 To UBound(arrPaths)
					strPathFolder = arrPaths(i) & "\"
					strPathFolder = Replace(strPathFolder, "\\", "\")
					strPathFolder = Replace(LCase(strPathFolder), "%systemroot%", _
					objShell.ExpandEnvironmentStrings("%systemroot%"))
					strHTML = strHTML & LCase(strPathFolder) & "<br />"
				Next
				Else strHTML = strHTML & strPath & "<br />"
			End If
			
			SystemPathSpan.InnerHTML = strHTML
			
			ShowDiv(NoPSExecArea)
			Exit Sub
		End If
		
		PreviewstrPCSpan.InnerHTML = strPC
		strPSExecLocationSpan.InnerHTML = strPSExecLocation
		
		ShowDiv(DataArea)
		PopulatePSExecSaveList(txtComputerName.Value)
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	PopulatePSExecSaveList(strPC)
    '#	PURPOSE........:	Populates the PSExec save list drop down box
    '#	ARGUMENTS......:	strPC = PC on which to perform action
    '#	EXAMPLE........:	PopulatePSExecSaveList(PC1)
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub PopulatePSExecSaveList(strPC)
		On Error Resume Next
		Dim arrPSExecSaves(9)
		arrPSExecSaves(0) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01")
		arrPSExecSaves(1) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02")
		arrPSExecSaves(2) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03")
		arrPSExecSaves(3) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04")
		arrPSExecSaves(4) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05")
		arrPSExecSaves(5) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06")
		arrPSExecSaves(6) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07")
		arrPSExecSaves(7) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08")
		arrPSExecSaves(8) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09")
		arrPSExecSaves(9) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10")
		
		For Each objOption in SaveList.Options
			objOption.RemoveNode
		Next 
		
		Set objOption = Document.createElement("OPTION")
		objOption.Text = ""
		objOption.Value = ""
		SaveList.Add(objOption)
		
		For i = 0 To 9
			If arrPSExecSaves(i) <> "" Then
				strCheckString = ""
				strPSExecSaveString = Replace(arrPSExecSaves(i), "strPC", strPC)
				arrPSExecSaveName = Split(strPSExecSaveString, "}{")
				strPSExecSaveName = arrPSExecSaveName(0)
				strPSExecSaveCommand = arrPSExecSaveName(1)
				strPSExecSaveVariables = arrPSExecSaveName(2)
				
				If strPSExecSaveVariables <> "" AND strPSExecSaveVariables <> " " Then _
					strPSExecSaveName = strPSExecSaveName & " " & strPSExecSaveVariables
				
				If InStr(LCase(strPSExecSaveCommand), "%comspec% /k") > 0 Then _
					strPSExecSaveName = strPSExecSaveName & " (Keep CMD)"
					
				strTitle = strPSExecSaveName
				
				Set objOption = Document.createElement("OPTION")
				objOption.Text = strPSExecSaveName
				objOption.Value = strPSExecSaveString
				objOption.Title = strTitle
				SaveList.Add(objOption)
			End If
		Next
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	OpenPSExecCommand(strPC)
    '#	PURPOSE........:	Opens the command specified in the PSExec save list
    '#	ARGUMENTS......:	strPC = PC on which to perform action
    '#	EXAMPLE........:	OpenPSExecCommand(PC1)
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub OpenPSExecCommand(strPC)
		strCheckCommand = ""
		ClearPSExecCommands txtComputerName.Value
		If SaveList.Value <> "" Then
			strSaveString = SaveList.Value
			arrSaveString = Split(strSaveString, "}{")
			strPreviewSaveCommand = arrSaveString(0)
			strExecuteSaveCommand = LCase(arrSaveString(1))
			strVariables = LCase(arrSaveString(2))
			arrCheckCommand = Split(strExecuteSaveCommand, " ")
			For i = 0 To UBound(arrCheckCommand)
				strCheckCommand = strCheckCommand & arrCheckCommand(i) & " "
				If LCase(arrCheckCommand(i)) = "\\" & LCase(strPC) Then Exit For
			Next
			
			arrUserValue = Split(strPreviewSaveCommand, " ")
			If InStr(strCheckCommand, "-i") > 0 Then Commands.cbxInteractive.Checked = True
			If InStr(LCase(strExecuteSaveCommand), "%comspec% /k") > 0 Then Commands.cbxCMD.Checked = True
			If InStr(strCheckCommand, "-e") > 0 Then Commands.cbxNotLoadProf.Checked = True
			If InStr(strCheckCommand, "-s") > 0 Then Commands.cbxSystem.Checked = True
			If InStr(strCheckCommand, "-s") > 0 Then 
				Commands.cbxSystem.Checked = True
				Commands.cbxUsername.Disabled = True
			End If
			If InStr(strCheckCommand, "-c") > 0 Then 
				Commands.cbxCopyFile.Checked = True
				Commands.cbxForceCopy.Disabled = False
				Commands.cbxNewerFile.Disabled = False
			End If
			If InStr(strCheckCommand, "-f") > 0 Then Commands.cbxForceCopy.Checked = True
			If InStr(strCheckCommand, "-v") > 0 Then Commands.cbxNewerFile.Checked = True
			If InStr(strCheckCommand, "-low") > 0 Then _
				Commands.PriorityChooser.Value = "low"
			If InStr(strCheckCommand, "-belownormal") > 0 Then _
				Commands.PriorityChooser.Value = "belownormal"
			If InStr(strCheckCommand, "-abovenormal") > 0 Then _
				Commands.PriorityChooser.Value = "abovenormal"
			If InStr(strCheckCommand, "-high") > 0 Then _
				Commands.PriorityChooser.Value = "high"
			If InStr(strCheckCommand, "-realtime") > 0 Then _
				Commands.PriorityChooser.Value = "realtime"
			If InStr(strCheckCommand, "-u") > 0 Then 
				Commands.cbxUsername.Checked = True
				For i = 0 to UBound(arrUserValue)
					If arrUserValue(i) = "-u" Then Commands.txtUsername.Value = arrUserValue(i + 1)
				Next
				Commands.txtPassword.Value = "******"
				Commands.txtUsername.className = "text"
				Commands.txtPassword.className = "text"
				Commands.txtUsername.Disabled = False
				Commands.txtPassword.Disabled = False
				Commands.cbxNotLoadProf.Disabled = False
				Commands.cbxSystem.Disabled = True
			End If
			For i = 0 to UBound(arrUserValue)
				If LCase(arrUserValue(i)) = "\\" & LCase(strPC) Then
					For x = i + 1 To UBound(arrUserValue)
						Commands.txtCommand.Value = Commands.txtCommand.Value & arrUserValue(x) & " "
					Next
					Exit For
				End If
			Next
			Commands.txtVariables.Value = strVariables
			ExecutePSExecCommand strPC, False, False, True
		End If
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	UpdatePSExecSaveCommands(strSaveString)
    '#	PURPOSE........:	Adds the current PSExec command into save list
	'#						registry value
    '#	ARGUMENTS......:	strSaveString = string value to be saved in
	'#						registry
    '#	EXAMPLE........:	UpdatePSExecSaveCommands("Preview}{Execute}")
    '#	NOTES..........:	Allows 10 commands to be saved
    '#--------------------------------------------------------------------------
	Sub UpdatePSExecSaveCommands(strSaveString)
		On Error Resume Next
		strSaveString = Trim(strSaveString)
		strPSExecSave01 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01")
		strPSExecSave02 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02")
		strPSExecSave03 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03")
		strPSExecSave04 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04")
		strPSExecSave05 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05")
		strPSExecSave06 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06")
		strPSExecSave07 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07")
		strPSExecSave08 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08")
		strPSExecSave09 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09")
		strPSExecSave10 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10")
		
		If strPSExecSave10 = "" Then
			objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10", strSaveString, "REG_SZ"
			PopulatePSExecSaveList(txtComputerName.Value)
			Exit Sub
		End If
		If strPSExecSave09 = "" Then
			If strPSExecSave10 <> strSaveString Then
				objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09", _
				strSaveString, "REG_SZ"
				PopulatePSExecSaveList(txtComputerName.Value)
				Exit Sub
			End If
		End If
		If strPSExecSave08 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08", _
					strSaveString, "REG_SZ"
					PopulatePSExecSaveList(txtComputerName.Value)
					Exit Sub
				End If
			End If
		End If
		If strPSExecSave07 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						objShell.RegWrite _
						"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07", _
						strSaveString, "REG_SZ"
						PopulatePSExecSaveList(txtComputerName.Value)
						Exit Sub
					End If
				End If
			End If
		End If
		If strPSExecSave06 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						If strPSExecSave07 <> strSaveString Then
							objShell.RegWrite _
							"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06", _
							strSaveString, "REG_SZ"
							PopulatePSExecSaveList(txtComputerName.Value)
							Exit Sub
						End If
					End If
				End If
			End If
		End If
		If strPSExecSave05 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						If strPSExecSave07 <> strSaveString Then
							If strPSExecSave06 <> strSaveString Then
								objShell.RegWrite _
								"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05", _
								strSaveString, "REG_SZ"
								PopulatePSExecSaveList(txtComputerName.Value)
								Exit Sub
							End If
						End If
					End If
				End If
			End If
		End If
		If strPSExecSave04 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						If strPSExecSave07 <> strSaveString Then
							If strPSExecSave06 <> strSaveString Then
								If strPSExecSave05 <> strSaveString Then
									objShell.RegWrite _
									"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04", _
									strSaveString, "REG_SZ"
									PopulatePSExecSaveList(txtComputerName.Value)
									Exit Sub
								End If
							End If
						End If
					End If
				End If
			End If
		End If
		If strPSExecSave03 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						If strPSExecSave07 <> strSaveString Then
							If strPSExecSave06 <> strSaveString Then
								If strPSExecSave05 <> strSaveString Then
									If strPSExecSave04 <> strSaveString Then
										objShell.RegWrite _
										"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03", _
										strSaveString, "REG_SZ"
										PopulatePSExecSaveList(txtComputerName.Value)
										Exit Sub
									End If
								End If
							End If
						End If
					End If
				End If
			End If
		End If
		If strPSExecSave02 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						If strPSExecSave07 <> strSaveString Then
							If strPSExecSave06 <> strSaveString Then
								If strPSExecSave05 <> strSaveString Then
									If strPSExecSave04 <> strSaveString Then
										If strPSExecSave03 <> strSaveString Then
											objShell.RegWrite _
											"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02", _
											strSaveString, "REG_SZ"
											PopulatePSExecSaveList(txtComputerName.Value)
											Exit Sub
										End If
									End If
								End If
							End If
						End If
					End If
				End If
			End If
		End If
		If strPSExecSave01 = "" Then
			If strPSExecSave10 <> strSaveString Then
				If strPSExecSave09 <> strSaveString Then
					If strPSExecSave08 <> strSaveString Then
						If strPSExecSave07 <> strSaveString Then
							If strPSExecSave06 <> strSaveString Then
								If strPSExecSave05 <> strSaveString Then
									If strPSExecSave04 <> strSaveString Then
										If strPSExecSave03 <> strSaveString Then
											If strPSExecSave02 <> strSaveString Then
												objShell.RegWrite _
												"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01", _
												strSaveString, "REG_SZ"
												PopulatePSExecSaveList(txtComputerName.Value)
												Exit Sub
											End If
										End If
									End If
								End If
							End If
						End If
					End If
				End If
			End If
		End If
		
		If strPSExecSave01 = strSaveString Then Exit Sub
		If strPSExecSave02 = strSaveString Then Exit Sub
		If strPSExecSave03 = strSaveString Then Exit Sub
		If strPSExecSave04 = strSaveString Then Exit Sub
		If strPSExecSave05 = strSaveString Then Exit Sub
		If strPSExecSave06 = strSaveString Then Exit Sub
		If strPSExecSave07 = strSaveString Then Exit Sub
		If strPSExecSave08 = strSaveString Then Exit Sub
		If strPSExecSave09 = strSaveString Then Exit Sub
		If strPSExecSave10 = strSaveString Then Exit Sub
		
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01", strSaveString, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02", strPSExecSave01, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03", strPSExecSave02, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04", strPSExecSave03, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05", strPSExecSave04, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06", strPSExecSave05, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07", strPSExecSave06, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08", strPSExecSave07, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09", strPSExecSave08, "REG_SZ"
		objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10", strPSExecSave09, "REG_SZ"
		
		PopulatePSExecSaveList(txtComputerName.Value)
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	ExecutePSExecSaveCommands(strPC, booRun, booSave, booOpen)
    '#	PURPOSE........:	Executes the PSExec command specified
    '#	ARGUMENTS......:	strPC = PC on which to perform action
	'#						booRun = boolean value to determine whether to
	'#						execute command (True) or not (False)
	'#						booSave = boolean value to determine whether to
	'#						Save command (True) or not (False)
	'#						booOpen = boolean value to determine whether to
	'#						Open command (True) or not (False)
    '#	EXAMPLE........:	ExecutePSExecSaveCommands PC1, True, False, False
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub ExecutePSExecCommand(strPC, booRun, booSave, booOpen)
		strPSExec = "psexec.exe "
		strComputer = "\\" & strPC & " "
		If Commands.txtCommand.Value <> "" Then
			strCommand = Trim(Commands.txtCommand.Value)
			If InStr(strCommand, " ") > 0 AND InStr(strCommand,Chr(34)) = 0 Then
				strCommand = Chr(34) & strCommand & Chr(34) & " "
				Else
					strCommand = strCommand & " "
			End If
		End If
		If Commands.txtVariables.Value <> "" Then _
			strVariables =  " " & Commands.txtVariables.Value
		If Commands.cbxInteractive.Checked Then
			If InStr(strSwitches, "-i") = 0 Then strSwitches = strSwitches & "-i "
			Else
				strSwitches = Replace(strSwitches, "-i", "")
		End If
		If Commands.cbxCMD.Checked Then
			strCMD = "%COMSPEC% /k "
			Else 
				strCMD = ""
		End If
		If Commands.cbxNotLoadProf.Checked Then
			If InStr(strSwitches, "-e") = 0 Then strSwitches = strSwitches & "-e "
			Else
				strSwitches = Replace(strSwitches, "-e", "")
		End If
		If Commands.cbxSystem.Checked Then
			If InStr(strSwitches, "-s") = 0 Then strSwitches = strSwitches & "-s "
			Commands.cbxUsername.Checked = False
			Commands.cbxUsername.Disabled = True
			Else
				Commands.cbxUsername.Disabled = False
				strSwitches = Replace(strSwitches, "-s", "")
		End If
		If Commands.cbxCopyFile.Checked Then
			If InStr(strSwitches, "-c") = 0 Then strSwitches = strSwitches & "-c "
			Commands.cbxForceCopy.Disabled = False
			Commands.cbxNewerFile.Disabled = False
			Else
				strSwitches = Replace(strSwitches, "-c", "")
				Commands.cbxForceCopy.Disabled = True
				Commands.cbxForceCopy.Checked = False
				Commands.cbxNewerFile.Disabled = True
				Commands.cbxNewerFile.Checked = False
		End If
		If Commands.cbxForceCopy.Checked Then
			If InStr(strSwitches, "-f") = 0 Then strSwitches = strSwitches & "-f "
			Else
				strSwitches = Replace(strSwitches, "-f", "")
		End If
		If Commands.cbxNewerFile.Checked Then
			If InStr(strSwitches, "-v") = 0 Then strSwitches = strSwitches & "-v "
			Else
				strSwitches = Replace(strSwitches, "-v", "")
		End If
		If Commands.PriorityChooser.Value <> "0" then 
			strPriority = "-" & Commands.PriorityChooser.Value & " "
		End If
		If Commands.cbxUsername.Checked Then
			Commands.txtUsername.className = "text"
			Commands.txtPassword.className = "text"
			Commands.txtUsername.Disabled = False
			Commands.txtPassword.Disabled = False
			Commands.cbxNotLoadProf.Disabled = False
			Commands.cbxSystem.Checked = False
			Commands.cbxSystem.Disabled = True
			On Error Goto 0
			If SaveList.Value <> "" Then
				strSaveString = SaveList.Value
				arrSaveString = Split(strSaveString, "}{")
				strExecuteCommand = arrSaveString(1)
				arrExecuteCommand = Split(strExecuteCommand, " ")
				For i = 0 To UBound(arrExecuteCommand)
					If arrExecuteCommand(i) = "-p" Then
						strPassword = arrExecuteCommand(i + 1)
						Exit For
					End If
				Next
				Commands.txtPassword.Value = strPassword
			End If
			If Commands.txtUsername.Value = "" Then
				strLoggedOn = LoggedOnUser(".")
				Commands.txtUsername.Value = strLoggedOn
			End If
			strUserName = "-u " & Commands.txtUsername.Value & " "
			If Commands.txtPassword.Value <> "" Then
				strUserVisiblePass = "-p ****** "
				strUserPass = "-p " & Commands.txtPassword.Value & " "
			End If
			Else
				Commands.txtUsername.className = "text disabled"
				Commands.txtPassword.className = "text disabled"
				Commands.txtUsername.Disabled = True
				Commands.txtPassword.Disabled = True
				Commands.cbxNotLoadProf.Disabled = True
				Commands.cbxSystem.Disabled = False
				Commands.txtUsername.Value = ""
				Commands.txtPassword.Value = ""
		End If

	
		strVisibleCommand = strPSExec & strSwitches & strUserName & strUserVisiblePass & _
		strPriority & strComputer & strCommand & strVariables
	
		strExecuteCommand = strPSExec & strSwitches & strUserName & _
		strUserPass & strPriority & strComputer & strCMD & strCommand & strVariables
		
		PreviewCommand.InnerHTML = strVisibleCommand
		
		If booOpen = False Then	SaveList.Value = ""
	
		If booSave = True Then
			If strUserPass <> "" Then
				PWPrompt = MsgBox("The password provided will be stored in clear text." & _
				vbCrLf & vbCrLf & "Are you sure you wish to do this?",vbYesNo+vbExclamation, _
				"PSExec Command Builder")
				If PWPrompt = vbNo Then
					Exit Sub
				End If
			End If
			strPreviewSaveCommand = Replace(strVisibleCommand, strPC, "strPC")
			strExecuteSaveCommand = Replace(strExecuteCommand, strPC, "strPC")
			
			If strVariables <> "" AND strVariables <> " " Then
				strPreviewSaveCommand = Replace(strPreviewSaveCommand, strVariables, "")
				strExecuteSaveCommand = Replace(strExecuteSaveCommand, strVariables, "")
				Else
					strVariables = ""
			End If
			
			strSaveString = Trim(strPreviewSaveCommand) & "}{" & Trim(strExecuteSaveCommand) & _
			"}{" & Trim(strVariables)
			
			UpdatePSExecSaveCommands(strSaveString)
		End If
		
		If booRun = True Then
			objShell.Run "%COMSPEC% /c " & strExecuteCommand
		End If
		
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	ClearPSExecCommands(strPC)
    '#	PURPOSE........:	Clears the PSExec form / preview
    '#	ARGUMENTS......:	strPC = PC on which to perform action
    '#	EXAMPLE........:	ClearPSExecCommandsPC1)
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub ClearPSExecCommands(strPC)
		With Commands
			.txtCommand.Value = ""
			.txtVariables.Value = ""
			.txtUsername.Value = ""
			.txtPassword.Value = ""
			.txtUsername.className = "text disabled"
			.txtPassword.className = "text disabled"
			.txtUsername.Disabled = True
			.txtPassword.Disabled = True
			.cbxInteractive.Checked = False
			.cbxNotLoadProf.Disabled = True
			.cbxNotLoadProf.Checked = False
			.cbxSystem.Disabled = False
			.cbxSystem.Checked = False
			.cbxCopyFile.Checked = False
			.cbxForceCopy.Checked = False
			.cbxForceCopy.Disabled = True
			.cbxNewerFile.Checked = False
			.cbxNewerFile.Disabled = True
			.cbxUsername.Checked = False
			.cbxUsername.Disabled = False
			.cbxCMD.Checked = False
			.PriorityChooser.Value = 0
		End With
		PreviewCommand.InnerHTML = "psexec.exe \\" & strPC
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	CopyPSExecCommand()
    '#	PURPOSE........:	Copies the content of the Preview area to the
	'#						clipboard
    '#	ARGUMENTS......:	
    '#	EXAMPLE........:	
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub CopyPSExecCommand()
		strCopy = PreviewCommand.InnerHTML
		document.parentwindow.clipboardData.SetData "text", strCopy
		MsgBox "The command has now been copied to the clipboard",vbInformation,"PSExec Command Builder"
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	ChangeUser()
    '#	PURPOSE........:	Action triggered on changing value in textbox
    '#	ARGUMENTS......:	
    '#	EXAMPLE........:	
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub ChangeUser()
		ClearPSExecCommands(txtComputerName.Value)
		ShowDiv(0)
	End Sub
	
	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	ShowDiv(objDiv)
    '#	PURPOSE........:	Changes display to show required screen
    '#	ARGUMENTS......:	objDiv = html div to show
    '#	EXAMPLE........:	ShowDiv(DataArea)
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub ShowDiv(objDiv)
		On Error Resume Next
		DataArea.className = "hidden"
		NotFoundArea.className = "hidden"
		NoPSExecArea.className = "hidden"
		
		objDiv.className = ""
	End Sub	

	'#--------------------------------------------------------------------------
    '#	SUBROUTINE.....:	Window_onLoad()
    '#	PURPOSE........:	Performs onLoad actions
    '#	ARGUMENTS......:	
    '#	EXAMPLE........:	
    '#	NOTES..........:	
    '#--------------------------------------------------------------------------
	Sub Window_onLoad
		self.ResizeTo 700,465
		VersionSpan.InnerHTML = objPSExecCommandBuilder.Version
		window.moveTo intLeft,intTop
	End Sub

	'#--------------------------------------------------------------------------
	'#  FUNCTION.......:	Reachable(strPC)
	'#  PURPOSE........:	Checks whether the remote PC is online
	'#  ARGUMENTS......:	strPC = PC on which to perform action
	'#  EXAMPLE........:	Reachable(PC1)
	'#  NOTES..........:  
	'#--------------------------------------------------------------------------
	Function Reachable(strPC)
		Set objWMIService2 = GetObject("winmgmts:\\.\root\cimv2")
		Set colPing = objWMIService2.ExecQuery _
			("Select * from Win32_PingStatus Where Address = '" & strPC & "'")
		For Each objItem in colPing
			If IsNull(objItem.StatusCode) Or objItem.Statuscode <> 0 Then
				Reachable = False
				Else
					Reachable = True
			End If
		Next
	End Function
	
	'#--------------------------------------------------------------------------
	'#  FUNCTION.......:	LoggedOnUser(strPC)
	'#  PURPOSE........:	Get the name of the logged on user as per WMI
	'#  ARGUMENTS......:	strPC = PC on which to perform action
	'#  EXAMPLE........:	LoggedOnUser(PC1)
	'#  NOTES..........:	
	'#--------------------------------------------------------------------------
	Function LoggedOnUser(strPC)
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
		strPC & "\root\cimv2")
		Set colComputer = objWMIService.ExecQuery _
			("Select * from Win32_ComputerSystem")
		For Each objItem In colComputer
			strLoggedOn = objItem.UserName
		Next
		LoggedOnUser = strLoggedOn
	End Function
	
</script>

<body>
	<table width="100%">
		<tr>
			<td>
				Computer Name:&nbsp;&nbsp;
				<input type="text" class="text" style="border-right:0px;border-width:2px;" tabindex="1" id="txtComputerName" size="15" onKeyUp="ChangeUser()"><input id="RunButton" class="button" type="button" style="height:23px;" tabindex="2" value="Select PC" name="btnCheck" onclick="RunPSExecCommand()" onMouseOver="btnCheck.className='button btnhov'" onMouseOut="btnCheck.className='button'">
			</td>
			<td style="text-align:right;font-size:0.9em;font-style:italic;font-weight:bold;font-size:0.9em;color:#888888;">
				Version <span id=VersionSpan>&nbsp;</span>&nbsp;&nbsp&nbsp;Created by Stuart Barrett
			</td>
		</tr>
	</table>
	<hr>
	<div id="DataArea" class="hidden">
		<div style="font-size:0.9em;font-style:italic;font-weight:bold;color:#888888;">
			Logged On User: <span id="LoggedOnSpan">&nbsp;</span>
		</div>
		<form name="Commands" method ="post">
		<table id="CommandsTable" style="width:100%;margin-top:0px;">
			<tr>
				<td>
					<table style="width:100%;">
						<tr>
							<td title="Command to be run">
								Command: 
							</td>
							<td title="Command to be run">
								<input type="text" class="text"  name="txtCommand" size="32" onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">&nbsp;&nbsp;&nbsp;
							</td>
							<td title="Command variables">
								Variables: 
							</td>
							<td title="Command variables">
								<input type="text" class="text"  name="txtVariables" size="32" onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
						</tr>
						<tr>
							<td title="Optional user name for login to remote system">
								Username: 
							</td>
							<td title="Optional user name for login to remote system">
								<input type="text" name="txtUsername" size="32" disabled=true class="text disabled" onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td title="Optional password for username, if left blank where a username is specified then you will be asked to supply one on executing the command">
								Password: 
							</td>
							<td title="Optional password for username, if left blank where a username is specified then you will be asked to supply one on executing the command">
								<input type="password" name="txtPassword" size="32" class="text disabled" disabled=true onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
						</tr>
						
						</tr>
						
					</table>
				</td>
			</tr>
			<tr><td>&nbsp;</td></tr>
			<tr>
				<td>
					<table width="100%">
						<tr>
							<td style="width:30%;" title="Run the program so that it interacts with the desktop of the  specified session on the remote system">
								Interactive
							</td>
							<td style="width:3%;" title="Run the program so that it interacts with the desktop of the  specified session on the remote system">
								<input type="checkbox" name="cbxInteractive" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td style="width:30%;" title="Does not load the specified account's profile">
								Do not load user profile
							</td>
							<td style="width:3%;" title="Does not load the specified account's profile">
								<input type="checkbox" name="cbxNotLoadProf" disabled=true onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td style="width:30%;" title="Run the remote process in the System account">
								Run as System
							</td>
							<td style="width:3%;" title="Run the remote process in the System account">
								<input type="checkbox" name="cbxSystem" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
						</tr>
						<tr>
							<td title="Copy the specified program to the remote system for execution">
								Copy file to remote host
							</td>
							<td title="Copy the specified program to the remote system for execution">
								<input type="checkbox" name="cbxCopyFile" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td title="Copy the specified program even if the file already exists on the remote system">
								Force copy
							</td>
							<td title="Copy the specified program even if the file already exists on the remote system">
								<input type="checkbox" name="cbxForceCopy" disabled=true onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td title="Copy the specified file only if it has a higher version number or is newer than the one on the remote system">
								Copy if file is newer
							</td>
							<td title="Copy the specified file only if it has a higher version number or is newer than the one on the remote system">
								<input type="checkbox" name="cbxNewerFile" disabled=true onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
						</tr>
						<tr>
							<td title="Optional user name for login to remote system">
								Alternate Username
							</td>
							<td title="Optional user name for login to remote system">
								<input type="checkbox" name="cbxUsername" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td title="Carries out the command specified by string and then the command Window remains (eg. for ipconfig)">
								Keep CMD on screen
							</td>
							<td title="Carries out the command specified by string and then the command Window remains (eg. for ipconfig)">
								<input type="checkbox" name="cbxCMD" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
							</td>
							<td title="Change the priority at which the process is run" colspan="2">
								Priority &nbsp;&nbsp;
								<select size="1" name="PriorityChooser" style="width:154px" onChange="ExecutePSExecCommand txtComputerName.Value, False, False, False">
									<option value="0"></option>
									<option value="low">Low</option>
									<option value="belownormal">Below Normal</option>
									<option value="abovenormal">Above Normal</option>
									<option value="high">High</option>
									<option value="realtime">Realtime</option>
								</select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</form>
		<p>
		Preview:
		<span style="background-color:white;width:100%;height:50px;border:1px solid black;padding:5px;" id="PreviewCommand">
			psexec.exe \\<span id="PreviewstrPCSpan">&nbsp;</span>
		</span>
		<p>
			<span style="float:left">
				<input id="runbutton" class="button" type="button" value="Execute" name="btnExecute" title="Execute command on PC" style="width:75px;" onClick="ExecutePSExecCommand txtComputerName.Value, True, False, False" onMouseOver="btnExecute.className='button btnhov'" onMouseOut="btnExecute.className='button'">
				&nbsp;&nbsp;
				<input id="runbutton" class="button" type="button" value="Clear" name="btnPSClear" title="Clear all PS Exec Commands" style="width:60px;border-right:0px;" onClick="ClearPSExecCommands txtComputerName.Value" onMouseOver="btnPSClear.className='button btnhov'" onMouseOut="btnPSClear.className='button'"><input id="runbutton" class="button" type="button" value="Copy" name="btnPSCopy" title="Copy PS Exec Command to clipboard" style="width:60px;border-right:0px;" onClick="CopyPSExecCommand" onMouseOver="btnPSCopy.className='button btnhov'" onMouseOut="btnPSCopy.className='button'"><input id="runbutton" class="button" type="button" value="Save" name="btnPSSave" title="Save PSExec command for future use" style="width:60px;" onClick="ExecutePSExecCommand txtComputerName.Value, False, True, False" onMouseOver="btnPSSave.className='button btnhov'" onMouseOut="btnPSSave.className='button'">
			</span>
			<span style="float:right;">
				Saved Commands: 
				<select size="1" name="SaveList" style="width:250px;" onChange="OpenPSExecCommand(txtComputerName.Value)">
				</select>
			</span>
		</p>
		<div style="font-style:italic;position:absolute;bottom:5px;right:10px;">
			<span style="font-weight:bold;">PSExec Location:</span> 
			<span id="strPSExecLocationSpan">&nbsp;</span>
		</div>
	</div>
	
	<div id="NotFoundArea" class="hidden">
		<span style="font-size:1.75em;font-weight:bold;color:red;">Access Error</span>
		<p>
			This PC cannot be reached or the Computer Name has been entered incorrectly.
		</p>
		<p>
			Please make sure you have entered the Computer Name correctly and try again.
		</p>
	</div>
	
	<div id="NoPSExecArea" class="hidden">
		<span style="font-size:1.75em;font-weight:bold;color:red;">PSExec Missing</span>
		<p>
			PSExec cannot be found in the System Path. The folders within your System Path are as below:
		</p>
		<span id="SystemPathSpan" style="height:170px;width:100%;overflow:auto;border:1px solid black;padding:5px;">&nbsp;</span>
		<br />
		You can download this utility from the following location:
		<p style="margin-top:5px;">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="[URL unfurl="true"]http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx"[/URL] title="Download PSExec" target="_blank">
				[URL unfurl="true"]http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx[/URL]
			</a>
		</p>
		Once you have downloaded PSExec you must place it into one of the above mentioned folders.
	</div>
</body>
</html>
 
I really appreciate the feedback.

Pretty much what I am trying to accomplish is below.

I work for an IT contract Customer Support team and each week we have an engineer who is "on call". There is about 5 webpages I have to go to (Customer monitoring, email alerts,etc.) and make changes to the user who is on call. I found a plugin for Firefox called iMacros which I have setup to go to each page and make all of the changes by just running one VBS per person. I want to setup a webpage that will call the VBS on a remote computer which in turn opens up Firefox then does the changes. All I need the webpage to do is when I click the button next to the persons name is run a VBS script that is located on another computer.

Any further help would be greatly appreciated.
 
perhaps you are better off just working out what the 'Post's to the webpages should be, the querystring to post to the webpage. well, i guess that relies on the webpages being simple Post html pages, sounds like they will be for IT customer support stuff :)

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
I was able to get a little further by using the schedulejob WMI but when it creates the job it puts it under the System account. Is there any way to change it to run under a certain user account.
 
the schedulejob with WMI just gets something to run with the task scheduler service? i presume you change change the properties of a scheduled task to run under a different user account / context? i think you can do this through the GUI so i presume the WMI class you mention exposes some properties for this?

i still think you are making life hard for yourself. psexec should work just fine, and even better than that investigate the automation of the POSTs to the webpages

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top