Page 1 of 1

change user

Posted: 02 Jul 2012 17:55
by Billd59
I am new to batch files. Just learning. I want to write a batch file to change my password. I know If I goto the start and go to ass and right click on command prompt and click runas administrator. I know how to change It than. I would like to know how to go to the administrator account with the batch file? For example I am In my account and want to go to the Administrator account with batch file. I also don't want the box to pop up.

Re: change user

Posted: 02 Jul 2012 20:39
by Dos_Probie
==To Change Administrator Password==
net user Administrator <password>

see script example below using "dostips" as password then log-off and backon with new pw.
You could use vbs script also to prompt you for password and do the same thing, without having to go in and type in a new password each time.

Code: Select all

@echo off
::CHANGE ADMIN PW ON THE FLY-NO CONSOLE CONFIRMATION::

::Change PW::
net user Administrator dostips>nul

::Logoff and backon with new password::
Shutdown -L

Re: change user

Posted: 02 Jul 2012 21:17
by Ed Dyreen
'
Dos_Probie wrote:

Code: Select all

net user Administrator dostips>nul
That will only work if the script already has elevated privileges.

One possible solution would be for your script to re-spawn itself using the runAs command to gain the required privileges.

Code: Select all

runAs /?
I must add to say that hard-coding passwords in scripts is a security risk but, an encryption tool should be easy enough to get your hands on.

Re: change user

Posted: 02 Jul 2012 23:00
by Dos_Probie
For elevated privileges you can always use:
8)

Code: Select all

::disable uac and supress prompt::
reg add "hklm\software\microsoft\windows\currentversion\policies\system" /v enableLUA /t REG_DWORD /d 0 /f
reg add "hklm\software\Wow6432Node\microsoft\windows\currentversion\policies\system" /v enableLUA /t REG_DWORD /d 0 /f
reg add "hklm\software\microsoft\windows\currentversion\policies\system" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f
reg add "hklm\software\Wow6432Node\microsoft\windows\currentversion\policies\system" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f

For specific file:
takeown /f "%systemroot%\pw.cmd"
icacls "%systemroot%\pw.cmd" %* /grant :r administrators:(OI)(CI)F:

Or just add the right-click "Run as Administrator" to your context menu.
http://www.davescomputertips.com/wp-con ... ership.txt