Need to run netsh command with elevated previledges
Hi Team,
I am running an script with netsh command for to enable file & print sharing module and that to only for an domain profile.
But when i try to call this command through VB script, it asks me to run that in elevated previledges.
PLease help me how do i achieve that, or is there any feasibility to invoke same in bat file itself, please let me know.
Regards,
Deepak Sharma.
Here are couple of URL that might help you :
http://stackoverflow.com/questions/17466681/how-to-run-vbs-as-administrator-from-vbs
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/310e57f9-2367-4293-9f97-53d0e077aacc/vb-script-to-run-a-batch-script-as-admin?forum=ITCG
http://www.server-world.info/en/note?os=Other&p=vbs
Arnav Sharma | http://arnavsharma.net/ Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading
the thread.
Similar Messages
-
How can you run a command with elevated rights on a remote server with invoke-command ?
I am trying to run a script on a remote server with invoke-command. The script is starting and is running fine, but the problem is that it should be running with elevated rights on the remote server. On the server where I start the invoke-command, my account has the necessary rights.
The server were I launch the invoke-command is a W2K8 R2. The remote box is a W2K3 with powershell v2.0 installed.
When I launch the script on the remote-box from the command line, I don't get the access denied's.
Is there a way to do this ?
Thanks in advanceThe script that I want to run is to install the windows updates. I get an access denied on the download of the updates.
When I execute the script on an W2K8 box, (not remotely) and I run it with non-elevated rights, I get the same error.
The script is running fine when it is launched on W2K3 box locally with a domain account that has local admin rights, or on a W2K8 R2 server with a domain account that has local admin rights, but with elevated rights.
Thanks in advance for your help.
#=== start script ====
param($installOption="TESTINSTALL",$rebootOption="NOREBOOT")
Function Show-Help
Write-Host ""
Write-Host "SCRIPT: $scriptName <installOption> <RebootOption>"
Write-Host ""
Write-Host "DESCRIPTION: Installatie van WSUS updates op de lokale server"
Write-Host ""
Write-Host "PARAMETERS"
Write-Host " -installOption <[INSTALL|TESTINSTALL]>"
Write-Host " -rebootOption <[REBOOT|NOREBOOT|REBOOT_IF_UPDATED]>"
Write-Host ""
Write-Host "EXAMPLE:"
Write-Host "$ScriptName -installOption INSTALL -rebootOption REBOOT_IF_UPDATED"
Write-Host "$ScriptNAme INSTALL NOREBOOT"
Write-Host ""
Write-Host "Indien beide parameter weggelaten worden zijn de defaultwaarden :"
Write-Host " installOption=TESTINSTALL "
Write-Host " RebootOption=NOREBOOT"
Write-Host ""
Exit
#Include alle globale variablen
$CEIF_WIN_PATH = (get-content env:CEIF_WIN_PATH)
$includeFile=$CEIF_WIN_PATH + "\Scripts\include_win.ps1"
. $includeFile
#initialiseer error count
$errcnt=0
$scriptName=$MyInvocation.MyCommand.Name
#argumenten controleren
$arrInstallOption= "TESTINSTALL", "INSTALL" # Mandatory variable with predefined values
If (!($arrInstallOption –contains $installOption)){ Show-Help }
$arrRebootOption = "REBOOT", "NOREBOOT","REBOOT_IF_UPDATED" # Mandatory variable with predefined values
If (!($arrRebootOption –contains $rebootOption)){ Show-Help }
#Logfile opbouwen
$logfile = get-logfileName($MyInvocation.MyCommand.Name)
Log-scriptStart $MyInvocation.MyCommand.Name $logfile
function Get-WIAStatusValue($value)
switch -exact ($value)
0 {"NotStarted"}
1 {"InProgress"}
2 {"Succeeded"}
3 {"SucceededWithErrors"}
4 {"Failed"}
5 {"Aborted"}
function boot-server()
if ($installOption -eq "TESTINSTALL")
logger "TESTINSTALL : - Reboot local Server" $logfile
else
logger " - Reboot local Server" $logfile
$thisServer = gwmi win32_operatingsystem
$thisServer.psbase.Scope.Options.EnablePrivileges = $true
$thisServer.Reboot()
$logmsg="Install option = " + $installOption + ", RebootOption = $rebootOption"
logger "$logmsg" $logfile
logger "" $logfile
logger " - Creating WU COM object" $logfile
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
logger " - Searching for Updates" $logfile
$SearchResult = $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")
logger " - Found [$($SearchResult.Updates.count)] Updates to Download and install" $logfile
$Updates=$($SearchResult.Updates.count)
logger "" $logfile
foreach($Update in $SearchResult.Updates)
if ($Update.EulaAccepted -eq 0)
$Update.AcceptEula()
# Add Update to Collection
$UpdatesCollection = New-Object -ComObject Microsoft.Update.UpdateColl
$UpdatesCollection.Add($Update) | out-null
if ($installOption -eq "TESTINSTALL")
else
# Download
logger " + Downloading Update $($Update.Title)" $logfile
$UpdatesDownloader = $UpdateSession.CreateUpdateDownloader()
$UpdatesDownloader.Updates = $UpdatesCollection
$DownloadResult = $UpdatesDownloader.Download()
$Message = " - Download {0}" -f (Get-WIAStatusValue $DownloadResult.ResultCode)
if ($DownloadResult.ResultCode -eq 4 )
{ $errcnt = 1 }
logger $message $logfile
# Install
logger " - Installing Update" $logfile
$UpdatesInstaller = $UpdateSession.CreateUpdateInstaller()
$UpdatesInstaller.Updates = $UpdatesCollection
$InstallResult = $UpdatesInstaller.Install()
$Message = " - Install {0}" -f (Get-WIAStatusValue $InstallResult.ResultCode)
if ($InstallResult.ResultCode -eq 4 )
{ $errcnt = 1 }
logger $message $logfile
logger "" $logfile
#Indien er een fout gebeurde tijdens download/installatie -> stuur mail naar windowsteam
if ( $errcnt -gt 0 )
logger " - Fout tijdens de uitvoering van script -> send mail" $logfile
$mailSubject=$MyInvocation.MyCommand.Name
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($logfile)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $mailFrom
$msg.To.Add($mailTo)
$msg.Subject = $mailSubject
$msg.Body = “Meer details in attachement”
$msg.Attachments.Add($att)
$smtp.Send($msg)
#Moet de server herstart worden ?
if ($rebootOption -eq "REBOOT_IF_UPDATED" )
if ($Updates -gt 0)
#Reboot the server when updates are installed
boot-server
elseif ($rebootOption -eq "REBOOT")
#reboot the server always
boot-server
else
#Do not reboot the server
logger "Do not reboot the server" $logfile
Log-scriptEnd $MyInvocation.MyCommand.Name $logfile
exit 0 -
dear all,
is it possible to run os commands with sql commands as follows :
SQL> ALTER system kill session '1764,60569'; ! kill -9 12151
2 /
ALTER system kill session '1764,60569'; ! kill -9 12151
ERROR at line 1:
ORA-00911: invalid character
kai
os version : solaris 5.10.. db : 10.2.0.4.0Kais,
What exact error are you getting running this script and what's OS (is it linux RH?? If you can post errors on running this script, that will be helpful. I tested on both cygwin (my desktop) and liunx box but you can change as needed) and to kill process from script you can use
echo `kill -9 pid`
Hope this helps
#!/bin/bash
typeset username=$1
function readSqlstmt {
typeset stmt=$1
echo "
set feedback off
set verify off
set heading off
set pagesize 0
whenever sqlerror exit 1
whenever oserror exit 2
$stmt;
exit
" | sqlplus -S '/as sysdba >> test.log
function killpid {
killpidsql=killpid.sql
sqlplus -s '/as sysdba' << ENDOFSQL >> test.log
whenever sqlerror exit 1
whenever oserror exit 2
SET pagesize 0
SET verify off
SET feedback off
SPOOL ${killpidsql}
SELECT 'ALTER system kill session ''' || s.sid || ',' || s.serial# || ''';'
FROM v\$session s, v\$process p
WHERE s.paddr = p.addr AND s.status = 'INACTIVE';
SPOOL OFF
@${killpidsql}
ENDOFSQL
killpid
readSqlstmt "SELECT p.spid FROM v\$session s, v\$process p WHERE s.paddr = p.addr AND s.status = 'INACTIVE'" | while read u
do
#echo "kill -9" $u >> test.log
echo "Killing inactive oracle process..."
echo `kill -9 $u`
done -
Need to run two commands in Runtime.getRuntime.exec()???
I need to run two commands in the same shell , in the same exec function... is this possible? I tried to invoke
ksh -e ... command1;command2
but that did nothingI need to run two commands in the same shell , in the
same exec function... is this possible? I tried to
invoke
ksh -e ... command1;command2
but that did nothingI'm not all that familiar with that particular shell (ksh), but if it works from the command-line, I'd venture to guess that it would have worked there as well. My guess is it did "work" (executed the 2 commands) but that you may have misdiagnosed the real problem (current working directory assumption incorrect, etc). -
How to run Unix command with Pipe ( | )?
Dear Friends,
I have to execute the below unix command through java program.
*ps -ewwo pid,args | grep -E "abc.sh|xyz.jar" | gawk '{ print $1 }' | wc -l*
My code to execute this command is,
Runtime run = Runtime.getRuntime();
File workDir = new File("/root/sat");
String psCmd = "ps -ewwo pid,args | grep -E \"abc.sh|xyz.jar \" | gawk '{ print $1 }' | wc -l";
Process process = run.exec(psCmd, null, workDir);
String line;
int i = process.waitFor() ;
if(i == 0) {
BufferedReader buf = new BufferedReader( new InputStreamReader( process.getInputStream() ) ) ;
while ( ( line = buf.readLine() ) != null )
System.out.println("Line - ["+line+"]") ;
} else {
BufferedReader stdErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// read the output from the command
while ((line = stdErr.readLine()) != null) {
System.out.println(line);
}When i execute this command, i'm getting output as,
ERROR: Garbage option.
When i analyse the above error, i found that, the PIPE ( | ) command is not supported through java.
Could anyone please help me how to execute the above unix command (with | ) in java?
Thanks in advance,
SathishThe pipe has to be interpreted by a shell so you need
String[] psCmd =
"sh",
"-c"
"ps -ewwo pid,args | grep -E \"abc.sh|xyz.jar \" | gawk '{ print $1 }' | wc -l"
Process process = run.exec(psCmd, null, workDir);You should also read, re-read and then implement the recommendations in the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html . -
SM69 command with elevation error
Hi,
I have a need to execute an SM69 configured command.
The command is "route delete X.X.X.X Y.Y.Y.Y"
On the server directly, I can do this without a problem.
Via SAP and the SM69 command, I get an error/trace : "The requested operation requires elevation"
( Executing the command "route print" is not a problem )
This would apparently mean that I need to run the cmd.exe application in Administrator mode.
Is there any way I can accomplish this via an additional parameter in SM69 ( my guess = no ), or do I need to make sure that the SID<System> user has more rights on the server itself?
Thanks for any input/views/guidelines.
Geert
PS the "route delete" issue is only relevant on win server 2008. On win server 2012, the issue is not present.Hi All,
Thanks a lot for your responses.
I think it was the basis issue. According to the basis the CPU was consuming 100% of the time & any new process was
getting in the loop. therefore yesterday even on JVM installed machine the MDX error was given.
I tried today & report is fetching the data correctly.
Thanks
Vinay -
Total nube to jws, need to run ssh command via web or jws?
Ok So we had a developer that created this application that can basically run ssh commands via jws I believe. Unfortunately he is no longer here. I am wondering how you do this? I know tha commands that are already set up, but I have no idea how to implement it into my project.
I am using Struts 2, Java 5, Weblogic 9.2, Spring
Thanks
orozcomHave a look at:
http://www.jcraft.com/jsch/
basically you'd need a small webstart client to wrap something like the above library. Best thing is to try with a standalone java client first. Once that is working have a look at turning it into a webstart app. -
Needing to run Mountain Lion with Yosemite OS
I'm needing to run Mountain Lion and I've got a new Retina 15" MBP that shipped with Yosemite. I've been told you cannot run it on a partition with Yosemite. What is the best way to go about doing this? I'm needing to have access to Pro Tools 10 as some of my plug ins aren't AAX compatible yet. Can this be done from a USB 3.0 drive or even Firewire 800 (via thunderbolt to FW800 adapter) if I do a bootable clone? I dunno if Boot Camp allows for this kind of operation or not. Any insight would be helpful.
Thanks,
AustinBootCamp is for running Windows on a Mac, not other Mac OS X versions.
The Mac computers ship with an EFI boot ROM that will not allow booting a version of Mac OS X older than that shipped on the Mac...which means, you cannot get your new MBPr to boot Mountain Lion since it shipped with Yosemite, two generations newer than what you want to run.
Best bet is contact the Power Tools folks and see if they have a version that is compatible with Yosemite. -
Running interactive command with Runtime.exec
I'm trying to run a command via the Runtime.exec interface.
Occasionally, the command needs to prompt for additional information. The response depends on the specific configuration, however, the command returns a list of options and then waits for a response.
However, when the command waits for the response, my Java app hangs.
After I call Runtime.exec, I create 2 threads to consume the contents of stderr and stdout. I then start them and call proc.waitFor()
I would expect to see the output of the command in the stdout stream even though the command hasn't exited. I had hoped to parse the output to determine the necessary response. However, the calls to read the contents of the stdout and stderr streams block and I never see any output.
How can I get access to the contents of those streams while the command is still running? Is this supported through the Runtime.exec interface?
Thanks,
ShawnThis article should help:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
User Defined Activity: Run OS Command with OS parameters
OS: OELR5 U3 x64
DB: 11.1.0.7
OWB: 11R1
I would like to be able to run an os command from a user defined activity within a process flow. I am trying to make use of VMWare's vmrun to control a virtual machine. From the OS command line I enter:
/usr/bin/vmrun -T server -h https://server:port/sdk -u user -p userpassword -gu guest -gp guestpassword runProgramInGuest "[standard] VM/Virtual Machine.vmx" -activeWindow -interactive "c:\path_to_program\program.exe" /switch
How many I duplicate this OS command from within a user defined activity in a process flow?
I create a user defined activity:
COMMAND: /usr/bin/vmrun
PARAMETER_LIST:
RESULT_CODE:
SCRIPT: -T server -h https://server:port/sdk -u user -p userpassword -gu guest -gp guestpassword runProgramInGuest "[standard] VM/Virtual Machine.vmx" -activeWindow -interactive "c:\path_to_program\program.exe" /switch
SUCCESS_THRESHOLD: 0
The process runs without error in the log, but the os command is not being run.
I tried again with:
COMMAND: /usr/bin/vmrun
PARAMETER_LIST: ?-T?server?-h?https://server:port/sdk?-u?user?-p userpassword?-gu?guest?-gp guestpassword?runProgramInGuest "[standard] VM/Virtual Machine.vmx"?-activeWindow?-interactive?"c:\path_to_program\program.exe"?/switch?
RESULT_CODE:
SCRIPT:
SUCCESS_THRESHOLD: 0
with the same result.
And I also tried calling sh:
COMMAND: bin/sh
PARAMETER_LIST:
RESULT_CODE:
SCRIPT: /usr/bin/vmrun -T server -h https://server:port/sdk -u user -p userpassword -gu guest -gp guestpassword runProgramInGuest "[standard] VM/Virtual Machine.vmx" -activeWindow -interactive "c:\path_to_program\program.exe" /switch
SUCCESS_THRESHOLD: 0
also with the same result.
The process runs in each case, and ends with: "Log file is available", but when I look in the log, I don't see errors or any information that might help me adjust the user defined activity.This method works:
COMMAND: bin/bash
PARAMETER_LIST:
RESULT_CODE:
SCRIPT: /usr/bin/vmrun -T server -h https://server:port/sdk -u user -p userpassword -gu guest -gp guestpassword runProgramInGuest "standard VM/Virtual Machine.vmx" -activeWindow -interactive "c:\path_to_program\program.exe" /switch
SUCCESS_THRESHOLD: 0
The issue seems to be caused on an upgrade to OWB 11R2. Our installation does not always update the VALUE entry when a user types in a value, meaning that our entry changes were not reflected into the deployed process package. -
Runtime.exec() I need to run a command prompt command from java.
the code i have that doesn't seem to work is:
String driveloc = System.getProperty("user.dir").substring( 0, 1 );
String path = jTextFieldPath.getText();
String path2 = jTextFieldPath.getText().substring(0, jTextFieldPath.getText().length()-3) + "lst";
String[] cmd = { "cmd.exe", "/" + driveloc, "ASMtools\\AS11 " + path + " -L >" + path2};
txt_mf.append( cmd[3] );
try {
Process np = Runtime.getRuntime().exec( cmd );
catch( java.io.IOException ioe) {
//error
}jTextFieldPath.getText() contains the path of the file saved by my program.
the line of code i am trying to run is:
AS11 FILE1 -L FILE2this line compiles the asm file and converts it to a lst creating an s19 file in the process. AS11 is an exe that aids the command prompt much like javac.
If you could help me figure this out it would be great.
Thanks in advance,
-JukeString driveloc =
System.getProperty("user.dir").substring( 0, 1 );
String[] cmd = { "cmd.exe", "/" + driveloc,
"ASMtools\\AS11 " + path + " -L >" + path2};Are you sure you want to invoke cmd.exe with the switch /c or /d or whatever depending on System.getProperty("user.dir") ?
Starts a new instance of the Windows 2000 command interpreter
CMD [A | /U] [Q] [D] [E:ON | /E:OFF] [F:ON | /F:OFF] [V:ON | /V:OFF]
[[S] [C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using c as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
/V:OFF Disable delayed environment expansion. -
Creating/running Terminal command with Automator
I am using Parallels Desktop on my iMac. Occasionally after I shutdown Parallels Desktop/Windows the ram it used is not released back, for example, depending on what I'm running in Parallels Desktop I can use upto around 16GB or ram. Ocassionally when I shutdown Windows and in doing that Parallels Desktop too, this ram level does not go back down. I find that going into Terminal and entering the purge command puts the ram level down to what it was before I loaded up Parallels Desktop.
I was wondering if its possible to use Automator to create a shortcut that I could then either place on my Desktop or Dock and when needed I could just double click on it and it would then load Terminal and then the purge command?
Or is there another way that I could automate the purge command?I managed to work it out for myself.
I done the following:
In Automator I chose Application/Run Shell Script. In the box that appeared in the right side I entered purge. I then saved it to my desired location and I then dragged it onto the Dock for easy access. -
Running Tasklist command with Administrator Priviledges
Hi,
I am trying to use tasklist command in my bat file to retrieve the list of users running some process say test.exe.
I am using following command in my bat file.
tasklist /v /fo table /nh /fi "IMAGENAME eq test.exe" > C:\temp\output.txt
When I run this bat file as administrator, it works fine and gives the names of users. But, when I run it as some other user, it will give UNKNOWN values in the username coulmn. I have given Full Rights to tasklist.exe in C:\Windows\System32 but still the
issue remains. How can I run the bat file with normal user privileges to get the Usernames?
Please help.
P.S:- I don't want to add the bat file in my Scheduled Task and run the the Task as administrator. That works, but I have to do this without going into making the Scheduled Task.
Bhushan ChandaHi Mandy,
Thanks for trying it out. Yes, I know I can use the Scheduled Tasks to run the bat file with Admin Privileges, but just thought, if there is a way round, that will make life of many easier.
Bhushan Chanda
Hi,
We could run TASKLIST /V to see details similar to what Task Manager shows. While Task Manager is limited to provide only local machine's information. So we could use a user of the local administrator group to list other user names.
For more detailed information, please refer to the article below:
Few must-know tools for basic system administration
http://sogeeky.blogspot.in/2006/06/few-must-know-tools-for-basic-system.html
Please Note: Since the website is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
Regards,
Mandy
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place. -
Need to run a PowerBook with NO INTERNAL display on an External display
So basically I have a TiBook that has had the display removed. I plan to run the machine using my lcd tv. Well, after hooking everything up, all I get is a blue screen. I'm assuming that the computer is looking for the original display. How can I have the computer ignore the internal and run off the external only?
Message was edited by: kipiscoolEasiest way would be to place a small magnet over the spot in the TiBook where the magnet sensor is that detects when the lid is down. Do you still have the display? You can fish for where the magnet is located behind the display by putting it face-up on a table and using a paper clip at the end of a thread or piece of dental floss. Wherever the magnet is, the sensor would be located opposite of it.
-
Need to run SQL jobs with Non Sys-Admin account
Hi Everyone,
We've recently asked to switch our SQL service account from an account having sysadmin permissions to a non sys-admin account. Could you please give us any inputs on this.
Thanks in advance. :)It's a little difficult to understand what you are talking about. First you say:
We've recently asked to switch our SQL service account from an account having sysadmin permissions to a non sys-admin account. Could you please give us any inputs on this.
No, the service account for SQL Server should not be a Windows administrator. It should be a standard Windows account. When you enter this account in SQL Server Configuration Manager, SSCM will assign the required permissions. You should then also assign
the permissions "Lock pages in memory" and "Perform volume maintenance tasks".
But then you start to talk about proxies and whatnots, and this is where you lose me entirely. Could you clarify what you are talking about?
Erland Sommarskog, SQL Server MVP, [email protected]
Maybe you are looking for
-
I opened my iPod Touch up to fix my home button. When i closed it back up it had a white screen. I tried pressing lock and home button for 10 seconds and it worked but while i'm using it it goes white with lines on the screen. Help please. This has b
-
I'm using my iPad with iOS 6.1.3. Is there a security patch for this version, or do I have to update to iOS 7.0.6?
-
My Apple ID used to set up gift iPad-how to change?
I bought my husband a surprise gift of an iPad. I wanted to set it up with some purchased apps and transfer photos from my MacBook Pro using my iTunes account. In order to do that, I had to use my Apple ID to set up the iPad, purchase the apps from i
-
After installing several updates, the system is unstable
Hello, I tried to install my mac mini server several times, all works fine, but after installing the updates from Apple update service, the VPN, Workgroup manager makes problems. In the last case I installed the last great update for the snow leopard
-
I am using a Java Web Start application to write and read files on a computer. When ever I try to run it, it says access denied. I have tried signing it, but that didn't work. Does anyone got an answer?