批处理文件…以管理员身份运行 [英] Batch File… running as administrator

查看:546
本文介绍了批处理文件…以管理员身份运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功创建了一个批处理文件来刷新DNS ...

I successfully created a batch file to flush my DNS…

我添加了一个暂停,我注意到在控制台窗口的标题栏中……它不是以管理员身份运行的.

I have added a pause, I noticed in the title bar of the console window… It's not running as administrator.

我已经尝试过几种变体了……一点点指导将不胜感激.

I've already tried a couple of variations of this… Just a little guidance would be most appreciated.

我记得在某个地方读过一个博客,上面写着大写字母并不重要……在编写批处理文件中,骆驼框是否很重要?

I remember reading a blog somewhere, it said something about capitalization wasn't important… Is camel casing important in writing batch files?

@echo off
echo.
pause
CD..
CD..
echo.
runas /user:<Administrator> ipconfig /flushdns
echo.
pause
echo.

推荐答案

要使用此方法运行命令,请键入以下命令之一:

To run your command with this method, type one of the following:

RUNAS /NOPROFILE /USER:computername/username "IPCONFIG /FLUSHDNS"
RUNAS /PROFILE /ENV /USER:domain/username "IPCONFIG /FLUSHDNS"
RUNAS /ENV /USER:username@domain "IPCONFIG /FLUSHDNS"

用适当的信息替换计算机名",用户名"和/或域".这些方法的问题在于它们需要管理员密码,而我无法在我的计算机上弄清楚该密码.但是,如果它类似于linux,则它是系统隐藏的随机生成的哈希.您可以尝试的另一种方法是:

Replace "computername", "username", and/or "domain" with the appropriate information. The problem with these methods are that they require an Administrator password, which I haven't been able to figure out on my machine. If it is anything like linux however, it is a randomly generated hash hidden by the system. Another method you can try is:

32位:

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "%HOMEDRIVE%\WINDOWS\System32\ipconfig.exe" /D RUNASADMIN

64位:

REG ADD "HKLM\SOFTWARE\WOW6432\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "%HOMEDRIVE%\WINDOWS\System32\ipconfig.exe" /D RUNASADMIN

此方法会将程序添加到注册表中,以便每次启动时都以管理员权限运行(兼容模式).只要您的目录不变,此方法就起作用.您必须在注册表中提供程序的直接路径.然后,您可以编写脚本,使其看起来像:

This method will add the program into the registry so it runs with administrator rights every time it launches (compatibility mode). This method only works as long as your directory does not change. You must supply the direct path to the program in your registry. You could then script to look something like:

@ECHO OFF
CD \
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "%HOMEDRIVE%\WINDOWS\System32\ipconfig.exe" /D RUNASADMIN
IPCONFIG /FLUSHDNS
PAUSE>NUL

希望这对您有所帮助.您可以检出

I hope this helps you out some. You can check out Verboon for more information on that REG ADD command and compatibility mode.

这篇关于批处理文件…以管理员身份运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆