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!

getting type mismatch at logonuser...any ideas?

Status
Not open for further replies.

scotitpulsa

IS-IT--Management
Oct 1, 2003
61
US
here is the snippet. if i don't have sub and end sub commmented out, it skips right over it...

'Sub main(args)
Dim user
Dim domain
Dim password
'' set these in your environment, or here in the script
'' If you're running as a service, you will need to set these
'' as SYSTEM variables

user = "**********"
domain = "**********"
password = "**********"

'' logon as user X
Dim hToken
hToken = LogonUser(user,domain,password) ',LOGON32_LOGON_BATCH,LOGON32_PROVIDER_DEFAULT)

'' Impersonate user X
Dim ilu
ilu = ImpersonateLoggedOnUser(hToken)

'' do whatever you want to do as user X
If ilu = true Then
'Print ("This thread is now running as " + user)
dim feedback_old, intranet_old, nextish_old, pulsabg_old

feedback_old = "c:\documents and settings\all users\desktop\feedback.url"
'intranet_old = "c:\documents and settings\all users\desktop\Rochester Intranet.url"
'nextish_old = "c:\nextish.ico"
'pulsabg_old = "c:\pulsabg.gif"

if fs.fileexists(feedback_old) = true then
set feedback_old = fs.GetFile(feedback_old)
feedback_old.delete
end if

'if fs.fileexists(intranet_old) = true then
' set intranet_old = fs.GetFile(intranet_old)
' intranet_old.delete
'end if

'if fs.fileexists(nextish_old) = true then
' set nextish_old = fs.GetFile(nextish_old)
' nextish_old.delete
'end if

'if fs.fileexists(pulsabg_old) = true then
' set pulsabg_old = fs.GetFile(pulsabg_old)
' pulsabg_old.delete
'end if
msgbox("impersonation succeeded")
Else
'Print ("Unable to become " + user)
msgbox("impersonation failed")
End If

'' all done with this user
FreeHandle(hToken)

'' terminate impersonation for this thread
RevertToSelf

'End Sub
 
' This code uses the security context of the administrator. The code should not be accessible to users.

' Declare variables
Dim objSWbemLocator, objSWbemService, objUser
Dim strCompAddr


strCompAddr = "."

' Set WBEM object variables
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemService = objSWbemLocator.ConnectServer(strCompAddr,,"administrator","passw0rd")

' YOUR CODE HERE

' Trap errors
If Err <> 0 Then
WScript.Echo "Unable to connect or modify file structure for " & strCompAddr & vbCrLf _
& "Reason: " & Err.Description
Else
WScript.Echo "File structure changed successfully for " & strCompAddr & vbCrLf
End If

'Release resources
Set objUser = Nothing
Set objSWbemLocator = Nothing
Set objSWbemService = Nothing


Paul

Work on Windows, play on Linux.
 
Clean it up a bit. Sorry.


On Error Resume Next

' Declare variables
Dim objSWbemLocator, objSWbemService, objUser
Dim strCompAddr


strCompAddr = "."

' Set WBEM object variables
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemService = objSWbemLocator.ConnectServer(strCompAddr,,"administrator","passw0rd")

' YOUR CODE HERE

' Trap errors
If Err <> 0 Then
WScript.Echo "Unable to connect or modify file structure for " & strCompAddr & vbCrLf _
& "Reason: " & Err.Description
Else
WScript.Echo "File structure changed successfully for " & strCompAddr & vbCrLf
End If

'Release resources
Set objSWbemLocator = Nothing
Set objSWbemService = Nothing

Paul

Work on Windows, play on Linux.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top