Jump to content

Help!


Recommended Posts

I am having a lot of trouble using @comspec with a variable. I need to add the computername as a user but it never seems to take the variable. But if I put in a word like "test" it works fine. Below is my poor excuse for the code. If anyone can help me this would be much appreciated. Thank you !! you can e-mail me if you would like @ tedescoj@gmail.com

Code:

$comp = @computername

Run(@ComSpec & " /c " net localgroup administrators $comp /add, "", @SW_HIDE)

Link to comment
Share on other sites

I am having a lot of trouble using @comspec with a variable. I need to add the computername as a user but it never seems to take the variable. But if I put in a word like "test" it works fine. Below is my poor excuse for the code. If anyone can help me this would be much appreciated. Thank you !! you can e-mail me if you would like @ tedescoj@gmail.com

Code:

$comp = @computername

Run(@ComSpec & " /c " net localgroup administrators $comp /add, "", @SW_HIDE)

1. I suggest you remove your e-mail address from your post by editing it, since otherwise spammer crawlers will read your e-mail address and spam you.

2. Try this:

Run(@ComSpec & " /c net localgroup administrators " & $comp & " /add", "", @SW_HIDE)

Note that to use the $comp variable, it needs to be OUTSIDE of the quotes. In your code it is inside the quotes, meaning it will be treated as part of the string. You need to concatenate using the & (ampersand) symbol. Also note that your '(....) @Comspec & " /c " net localgroup (....)' is wrong, the second quote needs to go. Look at the Run help, it contains a working example.

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

1. I suggest you remove your e-mail address from your post by editing it, since otherwise spammer crawlers will read your e-mail address and spam you.

2. Try this:

Run(@ComSpec & " /c net localgroup administrators " & $comp & " /add", "", @SW_HIDE)

Note that to use the $comp variable, it needs to be OUTSIDE of the quotes. In your code it is inside the quotes, meaning it will be treated as part of the string. You need to concatenate using the & (ampersand) symbol. Also note that your '(....) @Comspec & " /c " net localgroup (....)' is wrong, the second quote needs to go. Look at the Run help, it contains a working example.

Thank you fr your suggestion I will be sure not to add my e-mail address. The code you supplied is still not doing anything? it never adds a user. Any other suggestions? Thanks!!
Link to comment
Share on other sites

Thank you fr your suggestion I will be sure not to add my e-mail address. The code you supplied is still not doing anything? it never adds a user. Any other suggestions? Thanks!!

I guess this is because the net localgroup administrators /add is used to add users to the administrators group, not computers... But what I would do is not use the /c switch but the /k switch and changing @SW_HIDE to @SW_SHOW for troubleshooting purposes, so the dos box is visible and stays active and you can read the error output. For me when I try to add the computername to the admin group it tells me that the user does not exist (so it expects a user, not a computer name).

Try this:

Run(@ComSpec & " /k net localgroup administrators " & @ComputerName & " /add", "", @SW_SHOW)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...