I'm trying to make a script that you can input a workstation name and it will lock it remotely. I have found a few scripts that come close to what I'm trying to do, but none that do exactly what I want to do, so I attempted to make my own variation. I have super basic knowledge of VB but I'm quickly learning. I have taken some ideas from other scripts to get a feel for how things should work, and have come up with a vb embedded html page, but it doesn't fully work. I was wondering if someone could look at it and give me some pointers. Basically, the http form gets the workstation name and inputs that into the script that copies another vb script to the remote pc and executes it there. The VB script that gets copied is just a quick 2 liner I found that locks a workstation. My script seems to be hanging up on the variable for the workstation. If I put the workstation in the script manually, it works. Just not if it's a variable. The two in question are workstation and wrkstn. Those are pulled from the form. The code in between the '''''' is where it's hanging up. If I declare the variables workstation and wrkstn manually it works, for ex:
workstation = "\\computername\c$\windows\"
wrkstn = "computername"
Only when I pull them from the form it won't work. Any ideas? Here is the script.
<HTML>
<HEAD>
<TITLE>Workstation Lock Script</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!-- Add this to instruct non-IE browsers to skip over VBScript modules.
Option Explicit
Dim Wkstn 'workstation
Dim Workstation 'complete workstaion UNC Path
Sub cmdWorkstation_OnClick
Dim CRLF 'carrage return and line feed
Dim TABSPACE 'tab space
' constant values.
CRLF = Chr(13) & Chr(10)
TABSPACE = Chr(9)
' input from form defining workstation
Wkstn = Document.frmWorkstation.txtWorkstation.Value
' display the workstation and unc for diag reason
Workstation = "The workstation you just locked is:"
Workstation = Workstation & CRLF
Workstation = Workstation & TABSPACE & Wkstn & CRLF & CRLF
Workstation = Workstation & "The full path is:" & CRLF
Workstation = Workstation & TABSPACE & "\\" & Wkstn & "\c$\windows\"
MsgBox Workstation,,""
Const OverwriteExisting = TRUE
'''''''''''''''''''''''''''''
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\windows\winlck32.vbs", Workstation, OverWriteExisting
Set objWMIService = GetObject ("winmgmts:\\" & Wkstn & "\root\cimv2:Win32_Process")
Error = objWMIService.Create _
("cscript c:\windows\winlck32.vbs", null, null, intProcessID)
''''''''''''''''''''''''''''''
End Sub
</SCRIPT>
</HEAD>
<BODY>
<H1>Workstation Locker</H1>
<P>
This script will lock a remote workstation.
Just type in the persons computer and click "Lock It".
</P>
<FORM NAME="frmWorkstation">
<TABLE>
<TR>
<TD><B>Workstation:</B></TD>
<TD><INPUT TYPE="Text" NAME="txtWorkstation" SIZE=15></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="Button" NAME="cmdWorkstation" VALUE="Lock It">
</FORM>
</BODY>
</HTML>
workstation = "\\computername\c$\windows\"
wrkstn = "computername"
Only when I pull them from the form it won't work. Any ideas? Here is the script.
<HTML>
<HEAD>
<TITLE>Workstation Lock Script</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!-- Add this to instruct non-IE browsers to skip over VBScript modules.
Option Explicit
Dim Wkstn 'workstation
Dim Workstation 'complete workstaion UNC Path
Sub cmdWorkstation_OnClick
Dim CRLF 'carrage return and line feed
Dim TABSPACE 'tab space
' constant values.
CRLF = Chr(13) & Chr(10)
TABSPACE = Chr(9)
' input from form defining workstation
Wkstn = Document.frmWorkstation.txtWorkstation.Value
' display the workstation and unc for diag reason
Workstation = "The workstation you just locked is:"
Workstation = Workstation & CRLF
Workstation = Workstation & TABSPACE & Wkstn & CRLF & CRLF
Workstation = Workstation & "The full path is:" & CRLF
Workstation = Workstation & TABSPACE & "\\" & Wkstn & "\c$\windows\"
MsgBox Workstation,,""
Const OverwriteExisting = TRUE
'''''''''''''''''''''''''''''
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\windows\winlck32.vbs", Workstation, OverWriteExisting
Set objWMIService = GetObject ("winmgmts:\\" & Wkstn & "\root\cimv2:Win32_Process")
Error = objWMIService.Create _
("cscript c:\windows\winlck32.vbs", null, null, intProcessID)
''''''''''''''''''''''''''''''
End Sub
</SCRIPT>
</HEAD>
<BODY>
<H1>Workstation Locker</H1>
<P>
This script will lock a remote workstation.
Just type in the persons computer and click "Lock It".
</P>
<FORM NAME="frmWorkstation">
<TABLE>
<TR>
<TD><B>Workstation:</B></TD>
<TD><INPUT TYPE="Text" NAME="txtWorkstation" SIZE=15></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="Button" NAME="cmdWorkstation" VALUE="Lock It">
</FORM>
</BODY>
</HTML>