runas How to set user environment as current user? - windows

The currently logged in user is a standard user without administrator permission.
Run the Notepad program with the command: runas /profile /env /user:administrator "notepad.exe". Click the menu item and select Save as to open the file selection dialog box. In the dialog box, you can select the desktop file of the current user, but you cannot select a document folder or a download folder.
How can I read all the files of the current user when the computer program has an administrator?
Noprofile and profile are invalid. If env is not added, the current user's file cannot be read.
Can you specify to load a user's environment profile?
enter image description here

Related

Displaying the right username in PowerShell command prompt

When I open PowerShell, I see Delhivery as the username in the command prompt.
I want the PowerShell command prompt to display the username Hemanta like so: PS C:\Users\Hemanta>.
How can I do that?
Inside my users directory, I have the following directories.
I see a directory called Delhivery. Has this anything to do with the user name displayed in the command prompt?
EDIT-1
If I go to user accounts in Control Panel, I see the following:

How to run powershell from an elevated batch file to use current user?

So here's the case.
I'm in an a domain environment (Windows 7) where users are stripped from local administrator group. I created a batch file to install a program and it requires administrator privilege. After installation I want the program to be pinned to the current user start menu. The way I pinned it is by calling a powershell script from inside the batch file to do that.
So I can elevate the batch file to have admin privilege, but the problem is the program will not be pinned to the current user, and instead it is pinned for the admin user that I'm using to elevate the batch file. I'm guessing that this is because the powershell script was called from inside an elevated batch file, so it is also elevated.
Is there any way for me to achieve what I want without splitting the script?
I think that your problem is not about privileges or user.
You are probably editing the wrong environement to pin your program.
You should copy (or create) your shortcut in :
C:\Users\%USER%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

How to use RunAs Cmd to Launch Explorer, Windows 8

any idea why this is not working?
runas.exe /user:Administrator "cmd /c explorer"
it returns:
Windows cannot find the specified file. You may not have appropriate
permissions.
the following works by itself:
cmd /c explorer
thx!
Answer found here
http://winaero.com/blog/how-to-run-explorer-as-administrator-on-windows-8-1-windows-8-and-windows-7/
"Microsoft does not allow running Explorer as administrator in Windows 8.1/8 (and in Windows 7 too). The solution to run Explorer elevated...
1- take ownership of registry key below.
Right-click, Permissions, Advanced, Owner Change
or, Use Winaero's RegOwnershipEx application, which allows you to take ownership of registry keys
HKEY_CLASSES_ROOT\AppID{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}
2- rename or delete the value named 'RunAs'.
3- now Restore Ownership (this failed for me done manually-- i could not re-add TrustedInstaller --user not found).
4- at this point, you will be able to run explorer as admin
5- this process does not cleanly exit when you close the Explorer window! You must remember to terminate it every time you elevate Explorer after you are done working in the Explorer window.
Alternate solution: use Winaero's ELE.exe app to start any program as administrator from the command line.
Usually one wants to run as an Administrator to edit a file, or get permissions to delete a file:
To get to the permissions on a file you can right click on it and select Properties. Then select Security. You will see this dialog:
Then Click on Edit and change the permissions for the relevant user (e.g Mike).
You need to have admin privileges to do this, which can be set via User Account Control.
The File Permissions window looks like this:
Edit as required.
I have admin rights but Windows 8.1 still protects some system files (such as the Android studio.exe.vmoptions) and I used the above method to give me write access to the file.
Hope this helps.
You could always open a dos prompt as Administrator then go to the directory in question then do a Explorer . then it will open the location in question as the elevated user.

Task Scheduler (run whether user is logged on or not)

I'm having a problem with scheduling a task in Windows 7
I m creating a task which is mapped to a bat file to execute,
here is my .bat file :
cd "C:\soft\"
Start excel "" "AD Auto Run.xlsm"
its working automaticaly and manually when the option (radio button) "Run only when the user is logged on" is selected.
but the automatic/manual RUN is not working when the option (radio button) "Run whether user logged on or not" is selected.
I resolved the issue by performing these steps:
Create the empty Desktop folders at the below path:
C:\Windows\System32\config\systemprofile\Desktop C:\Windows\SysWOW64\config\systemprofile\Desktop
Make sure user has “log on as batch job” permission.
To enable this please follow below steps:
a) Go to the Start menu.
b) Type secpol.msc. and press Enter.
c) The Local Security Policy manager opens.
d) Go to Security Settings - Local Policies - User Rights Assignment node.
e) Double click Log on as a batch job on the right side.
f) Click Add User or Group.
g) Select the user.
h) Click OK.
Create a file and save it with .cmd extension. The .cmd file should contain below cmd:
cscript.exe “<path to .vbs file>”
In the scheduler, give the path as follows:
• Program/script: filename (.cmd filename)
• Start in(optional): file path (path to .cmd file)
Check the mapped drive in your batch file, by adding a diagnostic command after you map the drive.
Assuming M: is the mapped drive:
if exist "M:\soft\AD Auto Run.xlsm" (
>>"c:\folder with write permissions\file.log" echo map ok
) else (
>>"c:\folder with write permissions\file.log" echo map FAILED
)
I made some changes and it appears to work like a charm. The issue like I previously stated that the excel is creating some issue.
I found that the excel file was not able to save the record set output when the user account is logged off.
So You have to create a folder (or two on a 64bit-windows):
(32Bit, always)
C:\Windows\System32\config\systemprofile\Desktop
(64Bit)
C:\Windows\SysWOW64\config\systemprofile\Desktop
After creation of the folder, my program is working fine.

How to use runas command in windows 2008 r2 server?

I have written a batch file which will call another batch file and delete some files. For this I need to have admin rights. I tried following command...
runas /user:bala#nsc cmd
Enter the password for bala#nsc: xxxxxxx
Even though bala#nsc has admin rights command prompt is getting opened as a simple user rather than administrator.
I guess, I am missing something. Please help me.
Your results aren't what I expected, either. But I've got a few workarounds to suggest.
You could turn off User Account Control.
You could go to Start --> All Programs --> Accessories, then right-click on "Command Prompt" and choose "Run as Administrator."
You could right-click on your batch script and do the same.
You could create a shortcut to either cmd or your batch script on your Desktop, then modify the properties of that shortcut to run as Administrator.
You could add some code to your batch script to check for admin privileges and prompt for escalation if needed.
Turning off UAC would be my choice.

Resources