469,625 Members | 1,066 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Changing Computer Name with WMI

I'm trying to build code that allows the computer name to be changed, then asks the user to reboot to make the change affective. I got the code working when logged in as the local computer administrator or a domain administrator, but a regular domain user (with administrator privileges on the local machine) can't run the code successfully. They get error 1219, which I believe means "Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.".

If anyone can offer some advice or help I would very much appreciate it!

Here's my code:

Expand|Select|Wrap|Line Numbers
  2. Try
  3.                 Dim classInstance As New ManagementObject("root\CIMV2", "Win32_ComputerSystem.Name='" & currentCompName & "'", Nothing)
  4.                 Dim inParams As ManagementBaseObject = classInstance.GetMethodParameters("Rename")
  5.                 inParams("Name") = newCompName
  6.                 inParams("Password") = "adminpass"
  7.                 inParams("UserName") = "administrator"
  8.                 Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("Rename", inParams, Nothing)
  10.                 'If WMI returned 0 then success, otherwise report error.
  11.                 If outParams("ReturnValue") = 0 Then
  12.                     promptUser = MsgBox("Computer name changed to: " & newCompName & ". Change won't take effect until computer is restarted. Restart now?", MsgBoxStyle.YesNo)
  14.                     'Ask the user if they want to restart the computer.
  15.                     If promptUser = vbYes Then
  16.                         System.Diagnostics.Process.Start("ShutDown", "-t 1 /r")
  17.                     End If
  18.                 Else
  19.                     MessageBox.Show("WMI returned an error. Computer name not changed." & vbCrLf & vbCrLf & "ReturnValue: " & outParams("ReturnValue"), "WMI Error")
  20.                 End If
  21.             Catch err As ManagementException
  22.                 MessageBox.Show("WMI returned an error. Computer name not changed." & vbCrLf & vbCrLf & "Error: " & err.Message, "WMI Error")
  23.             End Try
Oct 4 '07 #1
0 1614

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by John Ryan | last post: by
1 post views Thread by Nick via .NET 247 | last post: by
4 posts views Thread by Acrobatic | last post: by
10 posts views Thread by 7stud | last post: by
reply views Thread by =?Utf-8?B?Z2FyeWRidXRsZXI=?= | last post: by
7 posts views Thread by Mtr | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.