Permissions Elevation for Windows 7? - windows

Ive got a java app which needs to execute a driver installer exe file. On Linux we type "gksudo myCommand". Is there a way to elevate permissions from Windows command line?

You may run every application in windows with a different user e.g. Administrator. But the user who executes this command needs to have the credentials to do so.
Edit.:
In advance you can lookup the User Account Control (UAC) which is available in Windows 7 and Vista if it is possibly an alternative for you.

I decided to deploy an executable binary onto the system which calls the jar. This way the user can right click and run as administrator... That didn't work... SO I kept looking... Check this out..
Elevate.exe.. It's basically like Windows GKSudo!!!!
http://www.robotronic.de/elevate.html
So... I packaged the 32bit exe into my program and deploy it, then run it as necessary.

You can use runas command like runas /user:Administrator myCommand (it requires the users to type password).
You can also use Start-Process cmdlet like Start-Process -Verb runas myCommand in PowerShell (it requires the users to click the UAC dialog).
see: http://satob.hatenablog.com/entry/2017/06/17/013217

Related

Is there a method of running an application as a standard user?

I am currently testing permissions as an administrator and need to test something as a standard user. There are ways to make standard users run as administrator, but I can't think of a way to run as a standard user as an administrator. If I were to remove my administrator rights, it would take awhile for IT to give me my admin rights back. Is there a better option that doesn't include setting up my dev environment as another user? I'm trying to run Visual Studio as a standard user, if that helps.
Thanks in advance
Create a file with the contents "filename.reg":
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\forcerunasinvoker]
#="Run without privilege elevation"
[HKEY_CLASSES_ROOT*\shell\forcerunasinvoker\command]
#="cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"%1\"\""
Run the file and apply registry changes, and then right click "Run without privilege elevation" on the file that needs to be tested. Found this solution from another thread! Thanks!

How to run batch file (As administrator) from Window Service

I have created a windows service, its running fine.
Now I would like to run a batch file as Administrator using windows service, because without administrator privileges it doesn't return any output.
So please let me know how can I do that. When I run directly using right click, run as administrator its working fine. Batch file as follows:
Runas.exe /noprofile /user:"Laxmilal Menaria" "lm.exe"
Thanks,
Laxmilal Menaria

Run jar file without admin rights

I have a runnable jar file, that I start with
java -jar myFile.jar
on Windows. A customer stated that he had problems starting the application (which is this jar file wrapped into an executable). I have the suspicion that it has something to do with admin rights. So I'd like to run my jar file without admin rights for testing purposes (because this way I get the System.out/err which helps greatly for debugging).
I realize that I can just create a non-admin account and start the application there, but I'd like to know if there is a way to specifically start a jar from an admin account so that it doesn't have admin rights in the console. Or alternatively: Is there a way to open up a console that has no admin rights from an admin account?
The customer uses Windows XP, so this is the operating system that I can use. (Although if you know something in a newer Windows like Win7, I appreciate it if you would tell me too).
EDIT: To clarify: I am looking for something like this
java -jar -runWithoutAdminRights myFile.jar
or
start /runWithoutAdminRights java -jar myFile.jar
or a way to open up a non-admin console from an admin account.
The Runas command definitely looks like the way to go.
I believe the way to go about this would be to first check the trust level options available to you:
runas /showtrustlevels
You should get something like the following:
C:\Windows\system32>runas /showtrustlevels
The following trust levels are available on your system:
0x20000 (Basic User)
You would then take the value for "Basic User" and run something like the following to start java:
runas /trustlevel:0x20000 "java -jar myFile.jar"
You can follow the below steps:
Log in as the Administrator
Open the command line
Go to System32 folder (cd C:/Windows/System32)
execute: runas /user:computer_domain_name\user1 cmd
You will be asked to provide the user1's password. Afterwards a new command line opens with the user1's rights.
I have tried it and it worked.
In conclusion you can write a very simple batch which performs the steps 2,3,4 automatically so that when you click it, a command line will open with the rights of another user.
I hope this helps.
edit registry is best way to run jar file with administrator automatically.
is easy if you have setup for java application.
go to following path in registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
create a key(String Value) with following specification:
ValueName: java path+javaw.exe(example c:\program files\java\jre7\bin\javaw.exe)
ValueData: "WINXPSP3 RUNASADMIN"
Now All Jar Files Runs to Administartor

PowerShell File monitor at Windows startup

I have a file system monitoring PowerShell script using System.IO.FileSystemWatcher events.
The script works great, but it requires an open PowerShell window.
Thus, I need to run it as a Windows Service at Windows startup (without logon). Is there a way to do this?
To execute your script at windows startup (without logon) you could create a windows service for it (using srvany.exe).
Steps:
Get the windows 2003 resource kit (which contains srvany.exe)
Install the resource kit
Create the service using sc and srvany.exe
sc create PSService binPath= "C:\Program Files\Windows Resource Kits\Tools\srvany.exe" DisplayName= "PSService"
Parametrize your service
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PSService]
"Type"=dword:00000010
"Start"=dword:00000003
"ErrorControl"=dword:00000001
"DisplayName"="PSService"
"ObjectName"="LocalSystem"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PSService\Parameters]
"Application"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -noExit -ExecutionPolicy RemoteSigned -File C:\\PSService\\psservice.ps1"
Some remarks:
Srvany.exe is not available for Windows Vista and up. It might work, but it's probably not supported
You might want to run it with other credentials (for security reasons)
You might want to save your script in a directory where only administrators have write access (for security reasons)

Why can't Perl launch telnet under Windows?

I had enabled telnet client feature on Windows 2008, and tried to launch it from a Perl script:
perl -e "system('c:\windows\system32\telnet localhost')"
Then I got an error like this:
'c:\windows\system32\telnet' is not recognized as an internal or external command,
operable program or batch file.
I could run it from 'cmd' terminal, or, if I copy the telnet.exe to local dir, it could be launched. I examined the permissions of telnet.exe under c:\windows\system32, no special finding.
Could anybody help me on this case? Thanks a lot!
I ran into the exact same problem recently, trying to launch telnet and the rdp client programmatically. The problem is related to an aspect of windows "design" called file system redirection:
"Windows on Windows 64-bit (WOW64) provides file system redirection. In a 64-bit version of Windows Server 2003 or of Windows XP, the %WinDir%\System32 folder is reserved for 64-bit applications. When a 32-bit application tries to access the System32 folder, access is redirected to the following folder: %WinDir%\SysWOW64. By default, file system redirection is enabled."
http://www.codeproject.com/tips/55290/Disabling-Windows-file-system-redirection-on-a-CFi.aspx
I think you have to specify the full name of the program, that is telnet.exe. But you'd be better off using Net::Telnet module or something like Expect.pm that handles interactive sessions programmatically.
hi you are using Perl, so i was wondering why you don't use Net::Telnet, instead of the telnet.exe of windows, which AFAIK is not friendly for programming.
On my computer following code works (Windows 7):
$telnet = $ENV{'WINDIR'} . '\system32\telnet.exe';
system("$telnet 192.168.1.1");
It must be either a) permissions b) incorrect path, c) you need .exe at the end or d) you need to capitalise the "c:"
You might want to verify under what account Perl execute and check if that account has permissions to run executables like telnet.
Just to verify the theory, I'd run Perl under a high privileged account (like admin) to check if it runs telnet and then tweak the account it is running under.
Hope this helps!
Read about console host.
ConHost represents a permanent change in the way that console application I/O is handled.
See also a related post on SysInternals forums.
I do not have access to any Windows Server 2008 machines right now, so I cannot test this, but can you check what happens when you run wperl -e "system('c:\windows\system32\telnet localhost')" from the equivalent of Start -> Run on that OS.
The answer is: using sysnative instead of system32, because the 32-bits application is not allowed to have access to the system32 directory (64-bit application). By using this alias sysnative it wil work.

Resources