Sign in to follow this  
Followers 0
drewdq

AutoIt and Netdom

7 posts in this topic

#1 ·  Posted (edited)

I'm looking to run the Microsoft netdom command, when I press a button in a GUI I am creating. Netdom is a command line tool which comes with the Remote Server Administration Tools for Windows 7. Normally, when you run netdom I get this output in Windows:

post-60550-128647887337_thumb.png

However, in my code, I am trying to execute this code:

#RequireAdmin
;....
Case $Button_Scripts_B3_RenameNetdom
            $OldHostname = InputBox("What Hostname?", "Please enter the taget hostname to rename", "oldName")
            $NewHostname = InputBox("What Hostname?", "Please enter the newname for $OldHostname", "newName")
            Run("netdom renamecomputer " & $OldHostname & " /newname:" & $NewHostname & " /reboot:1")

This doesn't work. I tried just launching a CMD window, to see if I could manually run netdom. The command prompt opens, but nothing happens when I try and run netdom.

If IsAdmin() Then
            Run("cmd")
            EndIf

post-60550-12864787763321_thumb.png

Anyone know how I can get this to work?

Edited by drewdq

Share this post


Link to post
Share on other sites



Maybe you should use it like this:

From the help file:

To run DOS (console) commands, try

Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE) ; don't forget " " before "/c"

If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Maybe you should use it like this:

From the help file:

To run DOS (console) commands, try

Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE) ; don't forget " " before "/c"

Thanks. I tried this with no luck. Nothing appeared to happen, even if the window was hidden it didn't work.

Run(@ComSpec & " /c " & "netdom renamecomputer " & $OldHostname & " /newname:" & $NewHostname & " /reboot:1", "", @SW_HIDE)

Also, I will need to be able to see the cmd window. Once the command is entered, there is a command line prompt which cannot be suppressed.

Edited by drewdq

Share this post


Link to post
Share on other sites

Thanks. I tried this with no luck. Nothing appeared to happen, even if the window was hidden it didn't work.

Run(@ComSpec & " /c " & "netdom renamecomputer " & $OldHostname & " /newname:" & $NewHostname & " /reboot:1", "", @SW_HIDE)

Also, I will need to be able to see the cmd window. Once the command is entered, there is a command line prompt which cannot be suppressed.

No need to let the command run hidden.

It was just a little example code, copied from the help file.

Are you running the script under an account with the right (admin) privileges?


If you learn from It, it's not a mistake

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Run(@ComSpec & " /c " & "netdom renamecomputer " & $OldHostname & " /newname:" & $NewHostname & " /reboot:1")

The above, seemingly opens and closes a cmd window without doing anything.

I am running this executable with an admin account, and have even added the

#RequireAdmin
, so UAC prompts for my approval before launching.

As a test I have even tried this:

Run("cmd")
WinWaitActive("C:\Windows\system32\cmd.exe")
Send("C:\Windows\System32\netdom.exe renamecomputer " & $OldHostname & " /newname:" & $NewHostname & " /reboot:1")
Send("{ENTER}")

It does not run in the CMD window that the gui launches. Ideas?

Edited by drewdq

Share this post


Link to post
Share on other sites

@drewdq

Are you sure netdom is in your system path? Also, do you have admin rights on the remote machine you are trying to rename? Do you have rights to rename the computer in the domain? Try using the /UserD, /PasswordD, /UserO, and /PasswordO options.

Try

Run("netdom renamecomputer " & $OldHostname & " /newname:" & $NewHostname & " /reboot:1", @SystemDir)

I have noticed that when using Run and RunWait with console apps, it is good to specify the directory they are located in as the working directory.

Adam

Share this post


Link to post
Share on other sites

Netdom is in my path, since it's in c:\windows\system32. Yes, I am using my domain admin account, but this is not the issue. I've been trying to launch a command window through my autoit gui that will let me run the netdom command. In my first post, on the second screenshot, you'll notice that running netdom does not return anything. If I run a cmd window as my admin account outside of the autoit script, it works fine.

I've tried specifying the username/password in the netdom tool, but the utility cannot be launched. Anyone else specifically try netdom in windows 7 through an autoit script?

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