tedescoj Posted April 13, 2007 Share Posted April 13, 2007 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 More sharing options...
SadBunny Posted April 13, 2007 Share Posted April 13, 2007 (edited) 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 April 13, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
tedescoj Posted April 13, 2007 Author Share Posted April 13, 2007 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 More sharing options...
SadBunny Posted April 13, 2007 Share Posted April 13, 2007 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 More sharing options...
jvanegmond Posted April 13, 2007 Share Posted April 13, 2007 Why did you make 2 topics? The question has even been answered several times, just Search! github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now