Re: passing variable to objShell.Run command
- From: chris.smaha@xxxxxxxxx
- Date: Tue, 15 Jan 2008 08:01:43 -0800 (PST)
On Jan 8, 3:48 pm, "Paul Randall" <paulr...@xxxxxxxxxxxx> wrote:
<chris.sm...@xxxxxxxxx> wrote in message
news:785e6020-30b8-4c96-a02d-2f87e95a74e5@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying to call a net user command from a VBScript and I am
having
trouble with passing a variable to that specific call (I'm planning
on
checking user objects for a home directory and clearing it if they
do).
Here's the script I'm working with:
Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject("LDAP://cn=user,ou=users,dc=test,dc=local")
Set objShell = CreateObject("Wscript.Shell")
'place home drive in variable
strHomeDrive = objUser.HomeDrive
strHomeDirectory = objUser.HomeDirectory
'if the home drive isn't empty clear it
if (isEmpty(strHomeDrive)) Then
'check to make sure the local path is empty as well
if(isEmpty(strHomeDirectory)) Then
Wscript.echo "Everything looks fine."
else
objShell.Run("%comspec% /k net user USERNAME /homedir:")
end if
end if
This works with no problem. What I would like it to do is this:
objShell.Run("%comspec% /k net user " & objUser & " /homedir:")
When I run this I get the following error message:
Microsoft VBScript runtime error: Wrong number of arguments or
invalid
property assignment.
Is there something I'm missing? How can I pass a variable to the
NET
USER command? Any suggestions are greatly appreciated.
Thanks in advance for your help.
When debugging problems like this, manually, in a command line window,
create a command string that works for any of your user names. Copy
that string from the command line window and put it in a message box
like this:
Msgbox "Working command is" & vbCrLf & _
"your working string goes here" & vbCrLf &
"Test command is: " & vbCrLf & _
"%comspec% /k net user " & objUser & " /homedir:"
After a few tries, noting the errors, and making fixes, you should be
able to come up with a solution like Pegasus posted.
Also, you need to understand that you are building a command line
string. Often you can include an object (which is way different from
a string) like objUser, because when you don't specify which property
of the object you are referring to, it presents a default property.
To be on the safe side, you should specify which property you want in
the string -- in this case objUser.name.
-Paul Randall
objUser.Name certainly cleared up the issue I was having and I thank
you both for that. The question I have now is "Can I CLEAR the home
directory and home drive for the User Object?". When I run the code
I've been using it prevents anything from being mapped to a specific
drive, but it still shows that there is a drive assigned when I run a
DSGET command on those users. (dsquery user -name USERNAME | dsget
user -hmdrv). I'm trying to avoid that.
I would LOVE to be able to set the path back to "Local" with no value
at all like it is when a new user is created, but for the life of me I
can't find that answer as to how to get that done. Does ANYONE have
ANY suggestions? Otherwise I'll have to use the code above and make
adjustments in queries looking for users with the home directory and
drive set.
Thanks again for all of the help. I TRULY appreciate it.
.
- Follow-Ups:
- Re: passing variable to objShell.Run command
- From: Paul Randall
- Re: passing variable to objShell.Run command
- References:
- passing variable to objShell.Run command
- From: chris . smaha
- Re: passing variable to objShell.Run command
- From: Paul Randall
- passing variable to objShell.Run command
- Prev by Date: Re: Using CopyHere to upload a folder to an FTP?
- Next by Date: script to tell which services the administrator account runs
- Previous by thread: Re: passing variable to objShell.Run command
- Next by thread: Re: passing variable to objShell.Run command
- Index(es):
Relevant Pages
|