[SOLVED]Help with a simple script...

Antworten
JayM
Beiträge: 5
Registriert: 23 Jan 2014, 13:47

[SOLVED]Help with a simple script...

Beitrag von JayM »

Hello again,

I'm starting to create a few simple scripts, but I'm having a bit of trouble. I'm trying to create a script to add a local user account to windows 7.

Here's the script:

Code: Alles auswählen

[Actions]
DefVar $username$
DefVar $fullname$
DefVar $password$
DefVar $isAdmin$
DefVar $syslanguage$

Set $username$ = GetProductProperty("user_name", "my_username")
Set $fullname$ = GetProductProperty("user_fullname", "my_fullname")
Set $password$ = GetProductProperty("password", "my_password")
Set $isAdmin$ = GetProductProperty("is_admin", "true")
Set $syslanguage$ = GetRegistryStringValue("[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Nls\Language] Default")

Message "Adding user to local machine"

winbatch_adduser

[winbatch_adduser]
if ($isAdmin$ = "true")

	net user $username$ $password$ /add /passwordreq:yes /fullname:"$fullname$"
	
	if ($syslanguage$ = "0816")
		net localgroup Administradores $username$ /add
	else
		net localgroup Administrators $username$ /add
	endif
	
else

	net user $username$ $password$ /add /passwordreq:yes /fullname:"$fullname$"

endif
Even though the script executes the net commands, it cannot interpret the "if" statements, and I always get the following error on the log:

Code: Alles auswählen

[5] [Fev 06 13:42:54:534] [win7-add-local-user] Execution of winbatch_adduser
[6] [Fev 06 13:42:54:534] [win7-add-local-user]   Call "if (False = "true")"
[6] [Fev 06 13:42:54:534] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:54:535] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:54:535] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute if (False = "true") : 2
[6] [Fev 06 13:42:54:535] [win7-add-local-user]   
[6] [Fev 06 13:42:54:536] [win7-add-local-user]   Call "net user test2 password /add /passwordreq:yes /fullname:"Test User 2""
[6] [Fev 06 13:42:54:536] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:54:536] [win7-add-local-user]   Start process as invoker: SYSTEM
[6] [Fev 06 13:42:55:551] [win7-add-local-user]   ExitCode 0    Executed process "net user test2 password /add /passwordreq:yes /fullname:"Test User 2""
[6] [Fev 06 13:42:55:551] [win7-add-local-user]   Call "if (0816 = "0816")"
[6] [Fev 06 13:42:55:551] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:55:552] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:55:552] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute if (0816 = "0816") : 2
[6] [Fev 06 13:42:55:553] [win7-add-local-user]   ExitCode 0    Executed process "net user test2 password /add /passwordreq:yes /fullname:"Test User 2""
[6] [Fev 06 13:42:55:553] [win7-add-local-user]   Call "net localgroup Administradores test2 /add"
[6] [Fev 06 13:42:55:553] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:55:553] [win7-add-local-user]   Start process as invoker: SYSTEM
[6] [Fev 06 13:42:56:570] [win7-add-local-user]   ExitCode 0    Executed process "net localgroup Administradores test2 /add"
[6] [Fev 06 13:42:56:570] [win7-add-local-user]   Call "else"
[6] [Fev 06 13:42:56:570] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:56:571] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:56:571] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute else : 2
[6] [Fev 06 13:42:56:571] [win7-add-local-user]   ExitCode 0    Executed process "net localgroup Administradores test2 /add"
[6] [Fev 06 13:42:56:571] [win7-add-local-user]   Call "net localgroup Administrators test2 /add"
[6] [Fev 06 13:42:56:571] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:56:571] [win7-add-local-user]   Start process as invoker: SYSTEM
[6] [Fev 06 13:42:57:588] [win7-add-local-user]   ExitCode 2    Executed process "net localgroup Administrators test2 /add"
[6] [Fev 06 13:42:57:588] [win7-add-local-user]   Call "endif"
[6] [Fev 06 13:42:57:588] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:57:588] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:57:589] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute endif : 2
[6] [Fev 06 13:42:57:589] [win7-add-local-user]   ExitCode 2    Executed process "net localgroup Administrators test2 /add"
[6] [Fev 06 13:42:57:589] [win7-add-local-user]   Call "else"
[6] [Fev 06 13:42:57:589] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:57:589] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:57:589] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute else : 2
[6] [Fev 06 13:42:57:589] [win7-add-local-user]   ExitCode 2    Executed process "net localgroup Administrators test2 /add"
[6] [Fev 06 13:42:57:589] [win7-add-local-user]   Call "net user test2 password /add /passwordreq:yes /fullname:"Test User 2""
[6] [Fev 06 13:42:57:589] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:57:590] [win7-add-local-user]   Start process as invoker: SYSTEM
[6] [Fev 06 13:42:58:606] [win7-add-local-user]   ExitCode 2    Executed process "net user test2 password /add /passwordreq:yes /fullname:"Test User 2""
[6] [Fev 06 13:42:58:606] [win7-add-local-user]   Call "endif"
[6] [Fev 06 13:42:58:606] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:58:606] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:58:607] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute endif : 2
[6] [Fev 06 13:42:58:607] [win7-add-local-user]   ExitCode 2    Executed process "net user test2 password /add /passwordreq:yes /fullname:"Test User 2""
[1] [Fev 06 13:42:58:610] [win7-add-local-user] ___________________
[1] [Fev 06 13:42:58:610] [win7-add-local-user] script finished
[1] [Fev 06 13:42:58:610] [win7-add-local-user] 6 errors
[1] [Fev 06 13:42:58:610] [win7-add-local-user] 0 warnings
The key error that keeps appearing is this one:

Code: Alles auswählen

[6] [Fev 06 13:42:54:534] [win7-add-local-user]   Call "if (False = "true")"
[6] [Fev 06 13:42:54:534] [win7-add-local-user]      Waiting until the called process is finished
[6] [Fev 06 13:42:54:535] [win7-add-local-user]   Start process as invoker: SYSTEM
[3] [Fev 06 13:42:54:535] [win7-add-local-user]   Exception in StartProcess_cp: Failed to execute if (False = "true") : 2
Can you spot what I'm doing wrong?

Thanks
Zuletzt geändert von JayM am 07 Feb 2014, 10:27, insgesamt 1-mal geändert.
dkoch
Beiträge: 309
Registriert: 25 Nov 2011, 14:03

Re: Help with a simple script...

Beitrag von dkoch »

Winbatch is for executing binaries. You can not use if-Statements in it. Put them into the actions section:

Code: Alles auswählen

....
winbatch_adduser

if ($isAdmin$ = "true")
  if ($syslanguage$ = "0816")
    Set $Admingrp$="Administradores"
  else
    Set $Admingrp$="Administrators"
  endif
winbatch_adduser_toadmins
endif

[winbatch_adduser]
net user $username$ $password$ /add /passwordreq:yes /fullname:"$fullname$"

[winbatch_adduser_toadmins]
net localgroup $Admingrp$ $username$ /add

JayM
Beiträge: 5
Registriert: 23 Jan 2014, 13:47

Re: Help with a simple script...

Beitrag von JayM »

Thank you very much!

It worked like a charm!

(I knew it should be some newbie mistake. Won't happen again (this one...))
Antworten