Re: passing variable to objShell.Run command

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
.



Relevant Pages

  • Re: passing variable to objShell.Run command
    ... When debugging problems like this, manually, in a command line ... create a command string that works for any of your user names. ... DSGET command on those users. ... adjustments in queries looking for users with the home directory and ...
    (microsoft.public.scripting.wsh)
  • TIP #185: Null Handling
    ... nulls, and command modifications for manipulating them. ... Tcl deals with strings, the universal medium for representing data. ... is know and it is an empty string, but if a respondent forgets to give ...
    (comp.lang.tcl)
  • Re: Determine how Word was launched
    ... inspect the command line used to launch Word. ... Private Declare Function GetCommandLineA Lib "kernel32" As Long ... Public Function GetCommandLineAs String ... Dim lngCmdLinePtr As Long ...
    (microsoft.public.office.developer.vba)
  • Re: Class.getMethod in classs static initializer block
    ... I just wanted to add that I had some similar code for a "command line server" project. ... static private final boolean DEBUG = true; ... {public ReturnCode runCommand(String s) ... public ReturnCode parseLine(String line) ...
    (comp.lang.java.programmer)
  • Re: New "base document" available
    ... How to go about retrieving command line parameters? ... the command line arguments (and environment variables) ... Keyword and positional parameters can be mixed in the same command line. ... clp-name points to a string containing "P1" ...
    (comp.lang.cobol)