WScript.Arguments issue - vbscript

I have a VBScript:
Set objUser = GetObject("WScript.Arguments.Item(0)")
objUser.TerminalServicesProfilePath = WScript.Arguments.Item(1)
objUser.AllowLogon = Enabled
objUser.SetInfo
This is called by:
wscript LDAPTSChanger.vbs LDAP://cn=Scott.Test,ou=Administration,dc=JPddRESS,dc=CO,dc=UK SCOMANTEST
But I can't get it to accept the WScript.Arguments.Item(0) as the search base (this will change per what's outputted elsewhere).
There is a space after the ldaptschanger.vbs to say its a parameter.

Remove the quotes:
Set objUser = GetObject(WScript.Arguments.Item(0))

Related

Find the owners of all the folders within a given path

I am trying to find the owners of all the folders in a given path. I have the following code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFolder In objFSO.GetFolder("C:\Windows").SubFolders
strpath = objFolder.Path
WScript.Echo strpath
Next
My end goal is to put the path and and owner of all the folders from the given path into a text file.
Could someone help me find the owner of a folder and be able to place this owner name into a variable. I could then use this to improve my existing code.
As JoSerra mentioned in the comments you can retrieve the owner of a file or folder via the WMI class Win32_LogicalFileSecuritySetting. The sample code from the Script Center is mostly accurate. I would, however, recommend using double quotes instead of single quotes around the path.
Single quotes (unlike double quotes) are valid characters in a path. If you invoke the statement wmi.Get("Win32_LogicalFileSecuritySetting.Path='" & path & "'") with a path containing a single quote, the call will fail with an "invalid object path" error. Thus it's better to use double quotes and escape backslashes in the path.
path = "C:\some\folder 'with' quotes"
Function Esc(str)
Esc = Replace(str, "\", "\\")
End Function
Set wmi = GetObject("winmgmts:")
Set fs = wmi.Get("Win32_LogicalFileSecuritySetting=""" & Esc(path) & """")
rc = fs.GetSecurityDescriptor(sd)
If rc = 0 Then
WScript.Echo "Owner: " & sd.Owner.Domain & "\" & sd.Owner.Name
Else
WScript.Echo "Couldn't retrieve security descriptor."
End If

VBS to run Multiple Macros

I am using this VBS to run a macro on an excel document that has several macros in it. Is there a way to run more than one macro on a single VBS or will I have to create several?
This is the code I am using.
strPath = "C:\Users\michael\Desktop\sced.xlsm"
strMacro = "Macro3"
Set objApp = CreateObject("Excel.Application")
objApp.Visible = True
Set wbToRun = objApp.Workbooks.Open(strPath)
objApp.Run strMacro
wbToRun.Save
wbToRun.Close
objApp.Quit
I was thinking that I would just be able to list the macros;
strMacro = "Macro3"
strMacro = "Macro4"
but it only runs the last macro on the list.
Thanks in advance.
Simplest solution for your needs is this:
strMacro1 = "Macro3"
strMacro2 = "Macro4"
strPath = "C:\Users\michael\Desktop\sced.xlsm"
Set objApp = CreateObject("Excel.Application")
objApp.Visible = True
Set wbToRun = objApp.Workbooks.Open(strPath)
objApp.Run strMacro1
objApp.Run strMacro2
wbToRun.Save
wbToRun.Close
objApp.Quit

If folder exist create shortcut this folder in MyDocuments VBS

I want to create a shortcut in my documents only if will be existed a network share.
I'm trying to solve for a long time, but i still have problem with this.
Any help or suggestions would be greatly appreciated.
Dim strSkanSou
Dim objMyDocuments
strSkanSou = "\\Network\Scan\%username%"
IF strSkanSou.FolderExists then
Set objShell = CreateObject("WScript.Shell")
objMyDocuments = objShell.SpecialFolders("MyDocuments")
Set objLink = objShell.CreateShortcut(objMyDocuments & "\Skaner.lnk")
objLink.Description = "Skaner"
objLink.TargetPath = strSkanSou
objLink.Save
End If
You've got most of it solved already. You just need to create a FileSystemObject to check for the existence of your folder. Replace:
IF strSkanSou.FolderExists then
With:
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strSkanSou) Then
Also, I see you're using the prefixes str for string and obj for object, which is great, but you may want to use strMyDocuments instead of objMyDocuments, since this is actually a string and not an object.

VBScript: Search remote registry to return SID and mapped share drives

I'm looking for some help creating script that would search for username in
ProfileImagePath string in Remote_Machine\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21*
and would get parent directory-the SID S-1-5-21*, store it in memory and later use it to output keys under
Remote_machine\HKEY_USERS*SID*\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2.
I was only able to find script:
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = InputBox("Please input PC name:","")'objNetwork.ComputerName
strLogonUser = objNetwork.UserName
Domaccount = trim(cstr(InputBox("Please input Domain User Account:","Type User_
Account")))
strDomain = "Dom"
Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\cimv2")
Set objAccount = objWMIService.Get ("Win32_UserAccount.Name='" & Domaccount &_
"',Domain='" & strDomain & "'")
Wscript.Echo objAccount.SID
but that one does not work all the time - I get SWbemServicesEx: Not found
and I think it uses different method than search. Moreover it does only first part of my request.
Can anyone help a brother out? :)
I am not sure to have understood your exact problem, anyway this hotfix released by Microsoft has been useful to me in a similar situation:
http://support.microsoft.com/kb/2465990

Get username from all users in specific group

I must be missing something here, or I'm blind or I've had too much coffee.
Basically, I'm trying to get the username of each user in a specific group i AD.
Then I want to take these username and pass those to a powershell script. But that's another case. This is probably a quick win for you guys.
Dim groupName
groupName = "LDAP://CN=groupname,OU=MailGroups,OU=Exchange,OU=MainContainer,DC=MyDomain,DC=com"
Set objGroup = GetObject(groupName)
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser.UserName)
Next
And I get this error message Object required: 'strUser'
Why is this happening? strUser is right there!
If I change the snippet a bit to this:
Set objGroup = GetObject(groupName)
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
msgbox objUser.Name
Next
Then I get the result CN=Doe John in the message box for each member.
try
For Each strUser in objGroup.Members
not Member but Member*s*
This site will tell you more than you ever want to know about AD and VBS:
http://www.computerperformance.co.uk/vbscript/vbscript_group_enumerate_members.htm

Resources