change user

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Billd59
Posts: 5
Joined: 02 Jul 2012 17:43

change user

#1 Post by Billd59 » 02 Jul 2012 17:55

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.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: change user

#2 Post by Dos_Probie » 02 Jul 2012 20:39

==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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: change user

#3 Post by Ed Dyreen » 02 Jul 2012 21:17

'
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.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: change user

#4 Post by Dos_Probie » 02 Jul 2012 23:00

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

Post Reply