您知道如果您是系统的管理用户,您可以右键单击"说",批处理脚本并以管理员身份运行它而不输入管理员密码吗?
我想知道如何使用PowerShell脚本执行此操作.我不想输入密码; 我只是想模仿右键单击Run As Administrator方法.
到目前为止我读到的所有内容都要求您提供管理员密码.
如何使用转义双引号替换批处理文件参数中的所有双引号?这是我当前的批处理文件,它扩展了字符串中的所有命令行参数:
@echo off
call bash --verbose -c "g++-linux-4.1 %*"
Run Code Online (Sandbox Code Playgroud)
然后它使用该字符串调用Cygwin的bash,执行Linux交叉编译器.不幸的是,我将这些参数传递给我的批处理文件:
"launch-linux-g++.bat" -ftemplate-depth-128 -O3 -finline-functions
-Wno-inline -Wall -DNDEBUG -c
-o "C:\Users\Me\Documents\Testing\SparseLib\bin\Win32\LinuxRelease\hello.o"
"c:\Users\Me\Documents\Testing\SparseLib\SparseLib\hello.cpp"
Run Code Online (Sandbox Code Playgroud)
传入第一个路径的第一个引用是过早地结束传递给GCC的字符串,并将其余参数直接传递给bash(这非常失败.)
我想如果我可以将参数连接成一个单独的字符串然后转义它应该正常工作的引号,但我很难确定如何做到这一点.有人知道吗?
当我输入命令
Start-Process powershell -WorkingDirectory "D:\folder"
Run Code Online (Sandbox Code Playgroud)
它打开带有D:\folder位置集的新PowerShell窗口.
但是当我输入命令时
Start-Process powershell -WorkingDirectory "D:\folder" -Verb RunAs
Run Code Online (Sandbox Code Playgroud)
它会打开新的PowerShell窗口管理员权限,但与C:\Windows\system32位置设置.
如何打开具有管理员权限的新PowerShell窗口并确定我自己的位置?
使用Start-Process,当Verb使用时,该Workingdirectory选项不起作用,新的 powershell 总是以C:\WINDOWS\system32. 为什么是这样?如果没有额外的cd命令,我怎么能做到这一点?
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.0
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.0
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\> Start-Process -FilePath powershell.exe -Verb Runas -WorkingDirectory C:\ws\
# the new ps shell always in system32:
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\WINDOWS\system32> pwd
Path
----
C:\WINDOWS\system32
Run Code Online (Sandbox Code Playgroud)