This source code does as the title suggests. It takes an input for PC and then it finds the user and then enumerates the printer share for that user.
forceUseCScript
Sub forceUseCScript()
Set oShell = CreateObject("Wscript.Shell")
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
oShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34),1,False
WScript.Quit 0
End If
End Sub
strComputer=inputbox("Enter PC Name")
CU=GetCurrentUser(strComputer)
CUSID = GetSIDFromUser(CU)
strKeyPath = CUSID & "\Printers\settings"
Const HKEY_USERS = &H80000003
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
oReg.EnumValues HKEY_USERS, strKeyPath, arrValueNames, arrValueTypes
For i=0 To UBound(arrValueNames)
StdOut.WriteLine "Printer: " & arrValueNames(i)
StdOut.Writeline "User: " & CU
StdOut.WriteBlankLines(1)
Next
'-----------------------------------------------------------------------
Function GetCurrentUser(strComputer)
'Input: strComputer = machine to query
'Output: Current User as domain\logon
'Only works on XP/W2003
on error resume next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each objProcess in colProcessList
objProcess.GetOwner strUserName, strUserDomain
Next
GetCurrentUser = strUserDomain & "\" & strUserName
if err<> 0 then
Msgbox " Error accessing remote machine"
wscript.quit
end if
on error goto 0
End Function
'-----------------------------------------------------------------------
Function GetSIDFromUser(UserName)
'Input: UserName as domain\logon
'Output: SID
'http://groups.google.com/...t/msg/1bd0d208ef41dda7
Dim DomainName, Result, WMIUser
If InStr(UserName, "\") > 0 Then
DomainName = Mid(UserName, 1, InStr(UserName, "\") - 1)
UserName = Mid(UserName, InStr(UserName, "\") + 1)
Else
DomainName = CreateObject("WScript.Network").UserDomain
End If
On Error Resume Next
Set WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!" _
& "/root/cimv2:Win32_UserAccount.Domain='" & DomainName & "'" _
& ",Name='" & UserName & "'")
If Err = 0 Then Result = WMIUser.SID Else Result = ""
On Error GoTo 0
GetSIDFromUser = Result
End Function
'-----------------------------------------------------------------------
Various Scripts and Application Code Segments for .NET, VB, C#, C++, C, Java, JavaScript, HTML, Python, Perl, AutoIT, Batch, ASP Classic, Objective-C, Swift, Unreal Engine 4, Unity3D & others. Also contains numerous IT tidbits, procedures, and tricks including Technology Hacks on various platforms.
Subscribe to:
Post Comments (Atom)
Generating "Always On Top" NSWindow in macOS across all detected displays
Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift Langues, you m...
-
In Unreal Engine 4 you will eventually need Linear Interpolation between two values to do something like ping pong between two float val...
-
Recently Possess () has been deprecated from UE4 , and when writing classes based on AAIController you have to use the function OnPossess ...
-
Often we intermingle C++ and Blueprints, and need for the two to communicate. With Behavior Trees, using ENUMs is an everyday occurrence an...
No comments:
Post a Comment