Testing this quick script

Started by pman, June 08, 2017, 09:41:19 AM

Previous topic - Next topic

pman

Hi-
I am extremely new to Winbatch, so hopefully these inquiries aren't to obtuse for this community.
I inherited a set of winbatch scripts from a former worker and trying to figure them out.
I was able to poach some script from the forums here http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Samples~from~Users+Rename~a~Computer~using~NETDOM.txt

I've edited it down for a very simple function, and am trying this out but it doesn't seem to be hitting the right mark, can anyone here hgive me some insight as to what I'm overlooking?
Thanks!


AddExtender("WWWNT34I.DLL")

:start

reg="SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName"
reg2="SYSTEM\ControlSet001\Control\ComputerName\ComputerName"
State = 0

name=Askline("Computer Name Change","Please Enter New Computer Name.","")

info=WinSysInfo()
computername=ItemExtract(1,info,@tab)

regkey=RegOpenKey(@REGMACHINE, reg)
RegSetvalue(regkey,"[ComputerName]",name) ; This is the new key that will be created.
  RegCloseKey(RegKey) ; The batch will now close the Reg key.


Display(2,"Computer Name Change","Changing Computer Name....")
delay(2)


     Display(5,"Computer Name Change","Computer name has been changed to %name%.")
:last

td

"Hitting the right mark" is a wonderful phrase but doesn't provide much useful information.  So is your script displaying an error and if so, what is the error?  Which version of Windows are you running the script on?  Which version of WinBatch are you using?  Is UAC enabled on the system?  Are you executing the script from an admin account?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pman

True - I'm more a wordsmith than a scriptor, :)

No error- just executes, prompts and completes without actually changing the hostname,
Windows version 8.1
Winbatch version 2016A
UAC disabled
Script executed as admin.

Thanks




td

Are you using Regedit to check the registry settings using Regedit or are you just assuming that the name has not change because some UI widget shows the old name?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pman

If I'm following your response, than- yes to check the old name and be able to place in the new.
This is a call post oobe imaging -which is getting the default windows name.
I'm just trying to save a few clicks. The problem is it doesn't appear to actually change the host name...
Ultimately I would be doing that and then description as well.     
Thanks

td

So how exactly are you checking the computer name after you run the script to determine that it (the script) is not changing the name?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pman

I've tried a few but this seems to verify.

result = ComputerNameGet(  0 )
Message( "The NetBIOS name of the local computer.", result )

or I just reboot and look at hostname.

I'm trying to poke this from a bunch of different angles, as I'm a novice at Winbatch. I have another thread which addresses the same problem using a couple of different methods.
http://forum.winbatch.com/index.php?action=profile;area=showposts;u=1369


The above asks in a nutshell:
Is there a way to Assign an askline= to a result=Computernameset( "Asklineinput", 0 ) ?

example:
name=Askline("Computer Name Change","Please Enter New Computer Name.","")
result = ComputerNameSet( "NAME I PUT INTO ASKLINE DIALOGUE",  0 )
Message( "ComputerNameSet", "Set the NetBIOS & Computer name of the local computer.")

I get the dialogue, but it doesn't seem to place "HOSTNAME I PUT INTO ASKLINE DIALOGUE" into the ComputerNameSet function (and rename the host ). Is there a call to I'm missing that will insert what I put in the dialogue?


Also, another method - could one do the same (insert the hostname using ComputerNameSet for a dialogue that writes a txt file?
example:


;;;Create a Log File
handle = FileOpen("C:\Sysinfodirectory\%pcname%.txt", "APPEND")
FileWrite(handle, "Install Date: %time1%")
FileWrite(handle, "Technician Name: %techln%,%techfn%")
FileWrite(handle, "Site Location: %techloc%")
FileWrite(handle, "")
Fileclose(handle)

;;;Change Computer Name
result = ComputerNameSet( pcname, 0 )
tshell:


This script would be the more desirable method to accomplish this task as it has a menu that can be filled by end user-and a record left behind.
My problem is that I'm not sure how to get handle = FileOpen("C:\Sysinfodirectory\%pcname%.txt", "APPEND") to actually insert just the filename (less the .txt extension)generated from user input  into the result = ComputerNameSet( pcname, 0 )

(it just names the host pcname, lol) I know this is ignorance of the software and have been trying to read into which got me this far at least.
Thanks!

td

Quote from: pman on June 08, 2017, 03:11:58 PM
I've tried a few but this seems to verify.

result = ComputerNameGet(  0 )
Message( "The NetBIOS name of the local computer.", result )

or I just reboot and look at hostname.

Not sure what you mean by "look at hostname" as it could mean one of several methods but you do have to modify about 7 or so registry settings to change a computer name.  The exact number depends on whether or not the compute is connected to a domain.

Of course question is why don't you just use "ComputerNameSet" with the appropriate parameter instead of fiddling with the registry?

Quote
I'm trying to poke this from a bunch of different angles, as I'm a novice at Winbatch. I have another thread which addresses the same problem using a couple of different methods.
http://forum.winbatch.com/index.php?action=profile;area=showposts;u=1369


The above asks in a nutshell:
Is there a way to Assign an askline= to a result=Computernameset( "Asklineinput", 0 ) ?

example:
name=Askline("Computer Name Change","Please Enter New Computer Name.","")
result = ComputerNameSet( "NAME I PUT INTO ASKLINE DIALOGUE",  0 )
Message( "ComputerNameSet", "Set the NetBIOS & Computer name of the local computer.")

I get the dialogue, but it doesn't seem to place "HOSTNAME I PUT INTO ASKLINE DIALOGUE" into the ComputerNameSet function (and rename the host ). Is there a call to I'm missing that will insert what I put in the dialogue?

JTaylor has already done a good job of explaining the cause of your problem.

Quote
Also, another method - could one do the same (insert the hostname using ComputerNameSet for a dialogue that writes a txt file?
example:


;;;Create a Log File
handle = FileOpen("C:\Sysinfodirectory\%pcname%.txt", "APPEND")
FileWrite(handle, "Install Date: %time1%")
FileWrite(handle, "Technician Name: %techln%,%techfn%")
FileWrite(handle, "Site Location: %techloc%")
FileWrite(handle, "")
Fileclose(handle)

As Jtaylor mentioned, since you are not an experienced user, don't use substitution. WinBatch has both the concatenation operator ": " and the "StrCat" function to build strings from variables.   

Quote
;;;Change Computer Name
result = ComputerNameSet( pcname, 0 )
tshell:


This script would be the more desirable method to accomplish this task as it has a menu that can be filled by end user-and a record left behind.
My problem is that I'm not sure how to get handle = FileOpen("C:\Sysinfodirectory\%pcname%.txt", "APPEND") to actually insert just the filename (less the .txt extension)generated from user input  into the result = ComputerNameSet( pcname, 0 )

(it just names the host pcname, lol) I know this is ignorance of the software and have been trying to read into which got me this far at least.
Thanks!

Not sure what you are trying to say by "has a menu that can be filled by end user".  Generally, menus are selected and not filled in.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade