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

Problem with variables in small script. I'm new at this.

Status
Not open for further replies.

ampm24

Technical User
Dec 1, 2001
16
US
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>
 
[1] minor note: you have "<!--" comment, but never closing it. Why?
[2] The workstation variable contains lots of junk not for copyfile method's consumption.
 
1. Don't know. Never noticed it. I haven't seen it closed in other scripts I looked at and assumed it was supposed to be that way. I'll close it out.

2. the workstation vaiable needs to be \\workstation\c$\windows\
so I added that stuff to the wrkstn variable which is just the workstation name. The message stuff was just so I could see what it was using as the variable, like an echo. Is there a more correct way to do this. The variable needs to be the full path for the copy file to work right?
 
[tt]Workstation="\\" & Wkstn & "\c$\windows\"
dim smsg
' display the workstation and unc for diag reason
smsg = "The workstation you just locked is:"
smsg = smsg & CRLF
smsg = smsg & TABSPACE & Wkstn & CRLF & CRLF
smsg = smsg & "The full path is:" & CRLF
smsg = smsg & TABSPACE & Workstation

MsgBox smsg,,""
[/tt]
 
Ok, I made the changes and also added:

Dim objFSO
Dim objWMIService

Now I get
Line:51
Char:1
Error: ActiveX component can't create object: 'GetObject'
Code:0

Any ideas, I think it's almost there. Thanx for the help.
 
OH sorry.

Set objWMIService = GetObject ("winmgmts:\\" & Wkstn & "\root\cimv2:Win32_Process")
 
Rename the htm/html extension to hta. It should be the security layer which blocks the getobject. As you use option explicit statement, apart from dim objFSO and objWMIService, any other variable not declared should be declared, like Error, for instance.
 
That worked. Thank you very much. I now know something I didn't before and I am grateful.
 
to take this one step further, i want to add a message variable that will pop up on the users computer, so when they unlock there PC, the message is there waiting for them telling them why they were locked. I added some more code to the script for this, with a text box on the form and added the variables, but the text box pops up on my PC not the remote one. I can't use net send because I block the messenger service in my network. Can echo be executed on the remote PC. I can repost the full code if you need to see it. But aside from adding a text box to the form and adding the variables for the message, that's it.

othermessage = Document.frmWorkstation.txtMessage.Value
Dim othermessage
I put the next line under
Set objWMIService = GetObject ("winmgmts:\\" & Wkstn & "\root\cimv2:Win32_Process")
MsgBox othermessage,,""

Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top