473,785 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing Computer Name with WMI

3 New Member
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 1921

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

Similar topics

2
2121
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 selection box can have varying amounts of entries, and this means theres a lot of white spaces in the second selection box sometimes. Is there any way to eliminate this? Here's my code: <script language="JavaScript1.2"> <!--
2
1490
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 read from a file i want to save the XML document in memory of the computer and when i am finished flush it back to the file, that
1
4704
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 based on a server name passed in, and whether ornot the PDA is in the active sync cradle. IE. If the PDA is in the cradle, use localhost. If the PDA isn'tin the cradle, then allow connection over wi-fi to any validwebservice by changing the computer...
4
5381
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 connectionStrings defined in my web.config file, one for the development db and another for the production db. When I publish my app to the hosting site, I rename the two connection strings so that the production string will be the active string in the...
4
2592
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 and empty). However, if I change the filename to something like "camera.jpg" and upload it, getimagesize() works perfectly, and I can print_r the array of data. PHP is uploading the files to my /var/temp directory just fine. Also, I have all...
10
4322
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 when I am connected to the internet, both the client and server hang and nothing happens. I discovered that the hostname of my computer automatically changes to that of my isp when I'm connected to the internet, and presumably the server program...
0
1254
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 name and possibly workgroup name. I can't seem to find any help on the subject anywhere. The machines will not be running Active Directory - Workgroup mode only. Thanks in advance.
4
2892
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
3962
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 appears in the envelope's Return-path: header? That value currently is the account_name@machine_name, but I don't want to give away my Linux account name with every single email.
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.