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

What am I doing wrong

Status
Not open for further replies.

DantanaSwat

IS-IT--Management
Dec 3, 2003
29
US
calling this logoff sub and its failing cos its not getting the strUser and strComputer from the rest of the script

sub logoff(noFile)
If objFSO.FileExists(noFile) Then
set objFile = objFSO.OpenTextFile(noFile,8)
else objFSO.CreateTextFile(noFile)
set objFile = objFSO.OpenTextFile(noFile, 8)
end If
objFile.WriteLine(strUser & "," & strComputer & "No")
objFile.Close

Set objWMIService = GetObject("winmgmts: {(4)}" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(4)
Next
end sub
 
Full script

'*********************************************************Pats lil login script***********************
'************************************************************Nov 21 2003******************************
'**************************************************create and set variables***************************


set WSHNetwork = WScript.CreateObject("WScript.Network")
set WSHShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
strUser = WSHNetwork.UserName
strComputer = WSHNetwork.ComputerName
strFolder = "x:\" & strUser
strFile = strFolder & "\" & strComputer & ".txt"
strNo = strFolder & "\" & "userNo.txt"
WSHNetwork.RemoveNetworkDrive("x:")
WSHNetwork.RemoveNetworkDrive("s:")

'************************************************drive mapping****************************************
WSHNetwork.MapNetworkDrive "S:", "\\cpq5500a\eia"
WSHNetwork.MapNetworkDrive "x:", "\\rhea\logins$"

'net time
WSHShell.Run "net time \\bigdell /set /y"

'***********check for Terminal Services and quit script if so while unmapping netlogin drive**********
Set WshSysEnv = WSHShell.Environment("PROCESS")
For Each obj In WshSysEnv
If InStr(obj, "WINSTATIONNAME") Then
unmap
WScript.Quit
End If
Next

'*****************check if folder userlog exists...if not then create it and the txt file*************
If objFSO.FolderExists(strFolder) Then
set objFile = objFSO.GetFile(strFile)
else objFSO.CreateFolder(strFolder)
objFSO.CreateTextFile(strFile)
set objFile = objFSO.GetFile(strFile)
end If

'****************************gets datediff between now and last time yesfile was modified*************
if datediff(&quot;d&quot;, Now, objFile.DateLastModified) < 1 Then
readfile
Else
end if

unmap
WScript.Quit


'*****************************************************************************************************
'************************************Functions Start Here*********************************************
'*****************************************************************************************************


'************************************msgBox functions*************************************************

sub msgHarass(ByVal strFile)
response = MsgBox(&quot;Welcome! We hope that you are having a great day!&quot; & vbCrLf & vbCrLf & &quot;We wanted to begin the day by reminding you about our company policy that covers harassment. Policy No. 703.&quot; _
& vbCrLf & vbCrLf & &quot;We do not believe that anyone should be subjected to any form of harassment. Harassment has been defined as any annoying act or actions that singles out an associate based on (but not limited to) race, color, religion, sex, age, national origin, disability, or veteran status.&quot; & vbCrLf & vbCrLf & &quot;If you are aware of any form of harassment that has happened or is happening, please let you Supervisor, Manager or Human Resources know immediately!&quot; & vbCrLf & vbCrLf & &quot;Click yes (You understand) or No (Logoff)&quot;, 4, &quot;Harassment Policy&quot;)
if response = 7 then
logoff
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine(strUser & &quot;,&quot; & now & &quot;,&quot; & strComputer & &quot;,&quot; & &quot;Harassment Policy&quot; & &quot;,&quot; & &quot;Yes&quot;)
objFile.Close
end if
End Sub

sub msgPhone(ByVal strFile)
response = MsgBox(&quot;Good Morning! Welcome!&quot; & vbCrLf & vbCrLf & _
&quot;We Just wanted to remind you about one of our company policies that we have that might affect you.&quot; _
& vbCrLf & &quot;The personal use of phone is limited to during lunch or break periods, prior to or after the scheduled workday, or for emergencies (infrequent and unexpected occurrences). Policy No. 504.&quot; _
& vbCrLf & &quot; If you have any questions, please contact your supervisor, manager or Human Resources.&quot; & vbCrLf & _
&quot;Have a great day!&quot; & vbCrLf & vbCrLf & &quot;Click yes (You understand) or No (Logoff)&quot;, 4164, &quot;Personnel Phone reminder&quot;)
if response = 7 then
logoff
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine(strUser & &quot;,&quot; & now & &quot;,&quot; & strComputer & &quot;,&quot; &&quot;Phone Policy&quot; & &quot;,&quot; & &quot;Yes&quot;)
objFile.Close
end if
End sub

sub msgComputer(ByVal strFile)
response = MsgBox(&quot;We are glad that you are here today!&quot; & vbCrLf & vbCrLf _
& &quot;We just wanted to give you a friendly reminder about our policy that discusses use of our business computers. We have asked that you not use the computer for solicitations, business ventures, religious, political, and/or offensive messages. Be careful and do not open pop ups. Only open recognized messages and be cautious about utilizing the 'preview pane' as it automatically opens up a message.&quot; & vbCrLf & vbCrLf & &quot;Interim intermittent infrequent personal use of our computers is allowed during breaks, lunch, before and after normal working hours. Policy No. 516.&quot; & vbCrLf & vbCrLf &&quot;Please Remember that erroneous email may contain computer virus! Help protect out systems!&quot; & vbCrLf & vbCrLf & &quot;Thank You.&quot; & vbCrLf & vbCrLf & &quot;Click yes (You understand) or No (Logoff)&quot;, 4164, &quot;Computer Usage Policy&quot;)
if response = 7 then
logoff
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine( strUser & &quot;,&quot; & now & &quot;,&quot; & strComputer & &quot;,&quot; & &quot;Computer Usage&quot; & &quot;,&quot; & &quot;Yes&quot;)
objFile.Close
end if
End sub

sub msgSubstance(ByVal strFile)
response = MsgBox(&quot;Hello - Welcome!&quot; & vbCrLf & vbCrLf &&quot;We just wanted to start your day with a friendly reminder about our company policy that covers drug and alcohol abuse. Our policy says that we conduct random drug and alcohol testing. We also conduct drug and alcohol testing when an accident occurs. We conduct these tests to assure that we are providing a safe place for you to work.&quot; _
& vbCrLf & vbCrLf & &quot;Should an associate refuse to submit to a drug of alcohol test, it may result in disciplinary action, up to and including termination of employment.&quot; _
& vbCrLf & vbCrLf & &quot;Any near miss or personal injury accident where an associate is taking someone else's prescription drugs will be treated as if the drugs were illegal and the associate will be subject to termination.&quot; & vbCrLf & vbCrLf & &quot;Click yes (You understand) or No (Logoff)&quot;, 4, &quot;Substance Abuse Policy&quot;)
if response = 7 then
logoff
else
set objFile = objFSO.OpenTextFile(strFile, 8)
objFile.WriteLine(strUser & &quot;,&quot; & now & &quot;,&quot; & strComputer & &quot;,&quot; & &quot;Substance Abuse&quot; & &quot;,&quot; & &quot;Yes&quot;)
objFile.Close
end if
End Sub



'***********************************************logoff function***************************************
sub logoff()
strUser = WSHNetwork.UserName
strComputer = WSHNetwork.ComputerName
If objFSO.FileExists(noFile) Then
set objFile = objFSO.OpenTextFile(noFile,8)
else objFSO.CreateTextFile(noFile)
set objFile = objFSO.OpenTextFile(noFile, 8)
end If
objFile.WriteLine(strUser & &quot;,&quot; & strComputer & &quot;No&quot;)
objFile.Close

Set objWMIService = GetObject(&quot;winmgmts: {(4)}&quot; & &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)

Set colOperatingSystems = objWMIService.ExecQuery (&quot;SELECT * FROM Win32_OperatingSystem&quot;)
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(4)
Next
end sub


'*************************************function to read logfile and send to appropriate function*******
sub readfile
set objFile = objFSO.OpenTextFile(strFile, 1)
Do until objFile.AtEndOfStream
strLine = objfile.ReadLine
Loop
if InStr(strLine, &quot;Harass&quot;) Then
msgPhone(strFile)
elseif InStr(strLine, &quot;Phone&quot;) Then
msgComputer(strFile)
elseIf InStr(strLine, &quot;Computer&quot;) Then
msgSubstance(strFile)
ElseIf InStr(strLine, &quot;Substance&quot;) Then
msgHarass (strFile)
Else
msgHarass(strFile)
End if
End sub

'****************************************unmap drives*************************************************
Sub unmap
WSHNetwork.RemoveNetworkDrive(&quot;x:&quot;)
End Sub
 
you logoff sub doesnt have a parameter passed to it so how does it know what noFile is?

where is the logoff sub called from, ok the msgbox subs but what calls them??
 
well if I do this
sub logoff(noFile)
If objFSO.FileExists(noFile) Then
set objFile = objFSO.OpenTextFile(noFile,8)
else objFSO.CreateTextFile(noFile)
set objFile = objFSO.OpenTextFile(noFile, 8)
end If
objFile.WriteLine(strUser & &quot;,&quot; & strComputer & &quot;No&quot;)
objFile.Close

strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:\\&quot; & &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colOperatingSystems = objWMIService.ExecQuery (&quot;SELECT * FROM Win32_OperatingSystem&quot;)
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(0)
Next
end sub

the strUser and strComputer are empty and it does not seem to want to work even if I do put them into the arguments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top