472,374 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

Changing Computer Name with WMI

3
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
  1.  
  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)
  9.  
  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)
  13.  
  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 1780

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

Similar topics

2
by: John Ryan | last post by:
I've a small bit of javascript on my site that has a from with 2 selection boxes, when you choose an option in the first box, the second one re-populates its list accordingly. But the second...
2
by: Gerald Maher | last post by:
Hi Reading in XML file, changing elements and saving back to the file, how can i do that, I want to be able to read an XML file and read out Elements. for example <name>Tom</tom> When I...
1
by: Nick via .NET 247 | last post by:
I have a similar problem trying to use web services with awindows form application. I currently use a static web referencein my project. What I am trying to do is to programaticallychange the url...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
4
by: Acrobatic | last post by:
I'm having troubles uploading an image and getting data from getimagesize(). When I upload a file with the name "20050914_loRes_XLH1.jpg", and do a getimagesize on it, it returns no info (null...
10
by: 7stud | last post by:
Hi, I'm experimenting with a basic socket program(from a book), and both the client and server programs are on my computer. In both programs, I call socket.gethostname(), but I discovered that...
0
by: =?Utf-8?B?Z2FyeWRidXRsZXI=?= | last post by:
I need to write an application which will allow us to take a freshly installed Windows XP system, let a user on an assembly line select a few options and then programmatically change the Computer...
4
bhing
by: bhing | last post by:
hi guys.. im new at installing fedora 5, i have a simple question, how do i change the name of the computer? example: :
7
by: Mtr | last post by:
Using the mail() function, I can easily change the From address that appears in an email. But how do I change the From that gets sent in the SMTP conversation, which results in the address that...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.