Change computer name from shell
Change computer name from shell
Change computer name from shell
Change computer name from shell
Change computer name from shell
Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell
Change computer name from shell Change computer name from shell
Change computer name from shell
Go Back  Xtreme Visual Basic Talk > > > Change computer name from shell


Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2011, 08:19 AM
croll12 croll12 is offline
Newcomer
 
Join Date: Nov 2011
Posts: 14
Default Change computer name from shell


I am having issues with changing the computer name from shell. Below is the code.

Dim _name = "%computername%"
Shell("wmic ComputerSystem Where Name=" + _name + " " + "Rename Name=" + "" + "station" + frmMain._station + "", vbHide, True)

I can get it to work if I replace _name with the actual computer name in quotes, however I will not know what the computer name is once this is in the field.

I have also tried:

Dim _name = My.Computer.Name
Shell("wmic ComputerSystem Where Name="" + _name + " " + "Rename Name=" + "" + "station" + frmMain._station + "", vbHide, True)

But that doesn't work either.

Any help would be greatly appreciated.
Reply With Quote
  #2  
Old 11-15-2011, 01:51 PM
jwshepherd jwshepherd is offline
Freshman
 
Join Date: May 2009
Location: West Texas
Posts: 45
Default

Not sure how to do it via the shell, but since you posted in the Net Section this sub will do it for you
Code:
 Private Sub changeName(ByVal s As String)
       Dim NEWLAB as string = UCase(s)
        Try
            Dim classInstance As New ManagementObject( "root\CIMV2", "Win32_ComputerSystem.Name='" & My.Computer.Name & "'", Nothing)
            Dim inParams As ManagementBaseObject = classInstance.GetMethodParameters("Rename")
            inParams("Name") = NEWLAB 'rename to
            ' inParams("Password") = "admin"
            ' inParams("UserName") = "administrator"
            Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("Rename", inParams, Nothing)
        Catch err As ManagementException
            MessageBox.Show("Error: " & err.Message)
        End Try
    End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Change computer name from shell
Change computer name from shell
Change computer name from shell Change computer name from shell
Change computer name from shell
Change computer name from shell
Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell Change computer name from shell
Change computer name from shell
Change computer name from shell
 
Change computer name from shell
Change computer name from shell
 
-->