473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1866

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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.