Sign in to follow this  
Followers 0
usera

shellexecute with "net user"

16 posts in this topic

Greeting,

I create a sample file as following: (I am administrator on this box), the goal is get the net user information in notepad,

Please let me know what is wrong, I use step by step in DOS it is ok.

#include <Date.au3>

#include <Inet.au3>

$UserName= InputBox("User name", "Enter the user name:", "", "*", 300, 140)

$Filename="C:\Userinfo.txt"

shellexecute("Net.exe", '" User " & $UserName & " /Domain >>" & $FileName')

shellexecute("notepad.exe", $FileName)

----------------------------------------------------------------------------------------------------------------------------

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <Date.au3>
#include <Inet.au3>
$UserName= InputBox("User name", "Enter the user name:", "", "*", 300, 140)
$Filename="C:\Userinfo.txt"
RunWait(@ComSpec & " /c " & "net user " & $UserName & " > " & $FileName)
shellexecute("notepad.exe", $FileName)

EDIT: what you did wrong was:

Shellexecute is the same as typing into the Start>Run dialog.

RunWait(@ComSpec & " /c " & <commands>) Is the same as running in "Dos box" IE cmd.exe (From help file on Run or RunWait)

Edited by danwilli

Share this post


Link to post
Share on other sites

Thanks for your reply,

I did change the code as you tell me. but for some reason, notepad give me nothing in the c:\userinfo.txt

any advises?

thanks

#include <Date.au3>
#include <Inet.au3>
$UserName= InputBox("User name", "Enter the user name:", "", "*", 300, 140)
$Filename="C:\Userinfo.txt"
RunWait(@ComSpec & " /c " & "net user " & $UserName & " > " & $FileName)
shellexecute("notepad.exe", $FileName)

EDIT: what you did wrong was:

Shellexecute is the same as typing into the Start>Run dialog.

RunWait(@ComSpec & " /c " & <commands>) Is the same as running in "Dos box" IE cmd.exe (From help file on Run or RunWait)

Share this post


Link to post
Share on other sites

If nothing is in the userinfo.txt then the user does not exist (or is being typed incorrectly)

I tested this on my XP box and a 2K3 server VM, both worked fine

Share this post


Link to post
Share on other sites

you are right, it works now.

Thank you very very much!

Thanks for your reply,

I did change the code as you tell me. but for some reason, notepad give me nothing in the c:\userinfo.txt

any advises?

thanks

Share this post


Link to post
Share on other sites

If nothing is in the userinfo.txt then the user does not exist (or is being typed incorrectly)

then you should have an error message in the text file!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

then you should have an error message in the text file!

Cheers

Kurt

Afraid not.... with an invalid user, you would just get a blank txt file, no error.

Share this post


Link to post
Share on other sites

Afraid not.... with an invalid user, you would just get a blank txt file, no error.

you're right. The command sends error messages to STDERR.

net user nosuchuser /domain > out.txt 2>err.txt

err.txt will contain the error message.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Any reason, I add /domain then I goto nothing in userinfo.txt?

could you please help me try in domain environment?

I did login in domain, before I am try that.

thanks

RunWait(@ComSpec & " /c " & "net user " & $UserName & " /domain> " & $FileName)

Sic semper tyrannis

*****

Group: Full Members

Posts: 886

Joined: 18-April 07

From: Eugene, OR, US

Member No.: 22,566

If nothing is in the userinfo.txt then the user does not exist (or is being typed incorrectly)

I tested this on my XP box and a 2K3 server VM, both worked fine

Edited by usera

Share this post


Link to post
Share on other sites

you're right. The command sends error messages to STDERR.

net user nosuchuser /domain > out.txt 2>err.txt

err.txt will contain the error message.

Cheers

Kurt

Hmmm... Did not know that you could do that.... thanks, that may come in useful in the future :D

Share this post


Link to post
Share on other sites

Any reason, I add /domain then I goto nothing in userinfo.txt?

could you please help me try in domain environment?

I did login in domain, before I am try that.

thanks

what's the output of the command if you run it in a DOS box?

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

what's the output of the command if you run it in a DOS box?

Cheers

Kurt

I got exactlly what I am looking for like:

The request will be processed at a domain controller for domain av.op

User name usera

Full Name usera

Comment user

User's comment

Country code 000 (System Default)

Account active Yes

Account expires Never

Password last set 11/5/2007 9:55 AM

Password expires 2/3/2008 9:55 AM

Password changeable 11/6/2007 9:55 AM

Password required Yes

User may change password Yes

Workstations allowed All

Logon script

User profile

Home directory \\rUsers\usera

Last logon 1/21/2007 10:38 AM

Logon hours allowed All

Local Group Memberships

Global Group memberships *Sales

The command completed successfully.

Update:

it works if I use c:\userinfo.txt. but it NOT if I user @UserProfileDir for the file location, I think it may be long directory name issue.

Edited by usera

Share this post


Link to post
Share on other sites

I got exactlly what I am looking for like:

assuming your code is O.K., you are probably not allowed to write to the file.

Try this:

#include <Constants.au3>

$UserName= InputBox("User name", "Enter the user name:", "", "*", 300, 140)
$pid= Run(@ComSpec & " /c net user " & $UserName & " /domain", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($pid)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($pid)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

assuming your code is O.K., you are probably not allowed to write to the file.

Try this:

#include <Constants.au3>

$UserName= InputBox("User name", "Enter the user name:", "", "*", 300, 140)
$pid= Run(@ComSpec & " /c net user " & $UserName & " /domain", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($pid)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($pid)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

Cheers

Kurt

Kurt,

Your codes are perfect. it work, But I really want to put the out to the user profile folder. as I said before I am the administrator, I have rights, it may be "c:\documents and settings" and "C:\docume~1" issue

thanks

Share this post


Link to post
Share on other sites

Kurt,

Your codes are perfect. it work, But I really want to put the out to the user profile folder. as I said before I am the administrator, I have rights, it may be "c:\documents and settings" and "C:\docume~1" issue

thanks

c:\documents and settings ?? O.K. I guess the assumption that your code is O.K. was simply wrong. Please post the EXACT code you are using!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Have you tried something liket this?

RunWait(@ComSpec & " /c " & "net user " & $UserName & " > " & """" & @UserProfileDir & "\" & $FileName &"""")

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0