// SendToQuickLaunch.js - Version 1.3
// Copyright (c) 2010, 2013 Bill Chatfield <[email protected]>
// All rights reserved.
var programDesc = "Send to Quick Launch";
var quickLaunchMenuItem = "Quick Launch (create shortcut)";
var installFolder = getEnvironmentVariable("AppData") + "\\" + programDesc;
var installedScript = installFolder + "\\" + WScript.ScriptName;
var shell = null;
var environment = null;
var fileSystem = null;
/* Returns a FileSystemObject object */
function getFileSystem() {
if (fileSystem == null) {
fileSystem = WScript.CreateObject("Scripting.FileSystemObject");
}
return fileSystem;
}
/* Returns a WshShell object */
function getShell() {
if (shell == null) {
shell = WScript.CreateObject("WScript.Shell");
}
return shell;
}
/* Returns a WshEnvironment object */
function getEnvironment() {
if (environment == null) {
environment = getShell().Environment("Process");
}
return environment;
}
/* Returns a String object */
function getEnvironmentVariable(name) {
var env = getEnvironment();
return env(name);
}
/* String */
function askOperation() {
// Ask the user if they want to install.
var answer = getShell().Popup("Install \"Quick Launch\" option in the \"Send To\" menu?", 300, programDesc + " - Admin", 4 + 32);
if (answer == 6) { // If Yes
return 'install';
}
var answer = getShell().Popup("Remove \"Quick Launch\" option from the \"Send To\" menu?", 300, programDesc + " - Admin", 4 + 32);
if (answer == 6) { // If Yes
return 'remove';
}
return '';
}
/* void */
function install() {
// Copy this script into its formal install folder.
if (! getFileSystem().FolderExists(installFolder)) {
getFileSystem().CreateFolder(installFolder);
}
// Destination folder must end in a backslash to be recognized as a folder.
getFileSystem().CopyFile(WScript.ScriptFullName, installFolder + "\\", true);
// Create the link in the SendTo folder that is invoked by the
// "Quick Launch" menu item on the "Send To" menu. This also
// creates the menu item beause Windows creates the "Send To"
// menu from whatever is in the "SendTo" special folder.
var sendToFolder = getShell().SpecialFolders("SendTo");
var link = getShell().CreateShortcut(sendToFolder + "\\" + quickLaunchMenuItem + ".lnk");
link.TargetPath = installedScript;
link.WindowStyle = 1;
link.IconLocation = "wscript.exe, 3"; // The yellow JavaScript icon is at index 3.
link.Description = programDesc;
link.WorkingDirectory = installFolder;
link.Save();
// Create a link in the Start Menu to allow uinstalling of this script.
var programsFolder = getShell().SpecialFolders("Programs");
var startMenuFolder = programsFolder + "\\" + programDesc;
if (! getFileSystem().FolderExists(startMenuFolder)) {
getFileSystem().CreateFolder(startMenuFolder);
}
var startMenuLink = getShell().CreateShortcut(startMenuFolder + "\\Uninstall " + programDesc + ".lnk");
startMenuLink.TargetPath = installedScript;
startMenuLink.Arguments = "--uninstall";
startMenuLink.WindowStyle = 1;
startMenuLink.IconLocation = "wscript.exe, 3";
startMenuLink.Description = "Uninstall " + programDesc;
startMenuLink.WorkingDirectory = installFolder;
startMenuLink.Save();
// Tell the user it was successful.
getShell().Popup("The installation is complete.", 300, programDesc + " - Admin", 64);
}
/* void */
function uninstall() {
// Uninstall Send To link.
var sendToFolder = getShell().SpecialFolders("SendTo");
var link = sendToFolder + "\\" + quickLaunchMenuItem + ".lnk";
if (getFileSystem().FileExists(link)) {
getFileSystem().DeleteFile(link);
}
// Uninstall file and folder in Program Files.
if (getFileSystem().FileExists(installedScript)) {
getFileSystem().DeleteFile(installedScript);
}
if (getFileSystem().FolderExists(installFolder)) {
getShell().CurrentDirectory = "C:\\"; // Move away so we can delete it.
getFileSystem().DeleteFolder(installFolder);
}
// Uninstall Start Menu link and folder.
var programsFolder = getShell().SpecialFolders("Programs");
var startMenuFolder = programsFolder + "\\" + programDesc;
var startMenuLink = startMenuFolder + "\\Uninstall " + programDesc + ".lnk";
if (getFileSystem().FileExists(startMenuLink)) {
getFileSystem().DeleteFile(startMenuLink);
}
if (getFileSystem().FolderExists(startMenuFolder)) {
getFileSystem().DeleteFolder(startMenuFolder);
}
getShell().Popup("It has been removed.", 300, programDesc + " - Admin", 64);
}
/* void */
function createQuickLaunchLinkFor(targetName) {
var target = getFileSystem().GetFile(targetName);
var link = getShell().CreateShortcut(buildShortcutFileName(target));
link.TargetPath = target.Path;
link.WindowStyle = 1;
link.Description = "Shortcut to " + target.Path;
link.WorkingDirectory = target.ParentFolder;
link.Save();
getShell().Popup("A shortcut to " + targetName + " was added to the Quick Launch menu.", 300, programDesc, 64);
}
/* String */
function buildShortcutFileName(/* File */ target) {
var homeDir = getEnvironmentVariable("USERPROFILE");
var quickLaunchDir = homeDir + "\\Desktop";
var name = quickLaunchDir + "\\" + target.Name;
var duplicateFileStartIndex = 2;
var i = duplicateFileStartIndex;
// Check for extensions that should be removed.
if (target.Type == "Application") {
// Remove the extension.
name = name.replace(/\.exe$/i, "");
}
else if (target.Type == "MS-DOS Batch File") {
// Remove the extension.
name = name.replace(/\.bat$/i, "");
}
// If the target is a Shortcut already, then do not append an additional
// link extension to the new Shortcut name. Else...
if (target.Type != "Shortcut") {
// The new Shortcut name does not have a ".lnk" Shortcut extension
// because the target didn't have one, so it needs one now.
name += ".lnk";
}
// Resolve Shortcut name conflicts.
while (getFileSystem().FileExists(name)) {
if (i == duplicateFileStartIndex) {
name = name.replace(/\.lnk$/i, "(" + i + ").lnk");
}
else {
name = name.replace(/\(\d+\)\.lnk$/i, "(" + i + ").lnk");
}
i++; // Increment index and try again.
}
return name;
}
/* Boolean */
function isUninstallSwitch(arg) {
var switches = new Array("--remove", "-remove", "--uninstall", "-uninstall");
var i;
for (i in switches) {
if (arg == switches[i]) {
return true;
}
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Main Program
//
/////////////////////////////////////////////////////////////////////////////
var targetName;
if (WScript.Arguments.length == 0) {
// If there is no argument, then perform an install or remove.
var op = askOperation();
if (op == 'install') {
install();
}
else if (op == 'remove') {
uninstall();
}
}
else {
// There is at least one command line argument.
targetName = WScript.Arguments(0);
if (isUninstallSwitch(targetName)) {
uninstall();
}
else {
// If we have an argument then we were invoked from the SendTo menu,
// so create a Quick Launch link for the given argument.
createQuickLaunchLinkFor(targetName);
}
}
请帮助查看文件创建成功后无法打开查看的问题所在。
dim fname
fname=InputBox("Enter File Name:")
MsgBox("The File name is " & fname)
' Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const ForReading = 1
Const OpenAsASCII = 0
Const OverwriteIfExist = -1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fResultFile = objFSO.CreateTextFile(fname & ".txt", _
OverwriteIfExist, OpenAsASCII)
Set objInputFile = objFSO.OpenTextFile("iplist.txt", ForReading)
arrIpList = Split(objInputFile.ReadAll, vbCrLf)
objInputFile.Close
For l = 0 To UBound(arrIpList)
strIP = Trim(arrIpList(l))
If strIP <> "" Then
If Not IsConnectible(strIP, "", "") Then
fResultFile.WriteLine strIP & " is down"
End If
End If
Next
' Open Result file
Set inCsvSys = CreateObject("Scripting.FileSystemObject")
Set inCsv = inCsvSys.OpenTextFile(fname & ".txt")
WScript.Echo "FIle found and opened successfully"
Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim oShell, oFSO, sTempFile, fFile
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
fFile.Close
oFSO.DeleteFile(sTempFile)
End Function
我有一个 VBScript 应该可以专注于一个给定的过程(取自这里):
Dim ObjShell :Set ObjShell = CreateObject("Wscript.Shell")
ObjShell.AppActivate("Notepad")
但不幸的是,这在使用特定进程的标题时不起作用:“Ableton Live 10 Intro.exe”是我认为的标题。
在这里,您可以在任务管理器中看到父进程名称为“Ableton Live 10 Intro.exe”(从“属性”面板复制粘贴)。我还注意到描述是“Ableton Live 10 Intro.exe”:
显然AppActivate()需要一个 PID 或标题字符串“因为它出现在标题栏中”,但出现在标题栏中的窗口标题是空的。我也不认为我可以使用 PID 来定位这个进程,因为我不知道 PID 是什么,因为这个脚本应该在这个进程在登录时启动时发生(因此 PID 每次都会不同)。
那么,鉴于我有它,我该如何定位这个过程
- 描述,
- 可执行文件的路径,
但不是它
- 标题,
- PID
这甚至可能吗?我是 VBScript 的新手。谢谢你的帮助!
我有一个包含很多子文件夹的文件夹“文档”。这些子文件夹下有文件。
我的目标是将文件移动到一个文件夹位置,然后在某个时候能够将它们移回它们来自的子文件夹。
我的一般想法是在移动后将子文件夹名称附加到文件的开头。然后在需要将它们移回其源子文件夹时,可以将其用作参考。
这是可行的,还是您对我如何实现这一目标有任何其他想法?我只知道如何在 VBA 中移动/复制文件。
这是我使用的当前代码:
Fldr= "C:\Documents"
Set fs=createobject("scripting.filesystemobject")
Set f=fs.getfolder(Fldr)
Set fsub=f.subfolders
For each f in fc
Subfolderspec=Fldr&"\"&f.name
fs.copyfile Subfolderspec & "*.*", "C:\Test"
On Error Resume Next
Next
我找到了以下 vbs 脚本来获取屏幕分辨率
但我想将结果保存在文本文件中,请帮助我
Dim HTM, wWidth, wHeight
Set HTM = CreateObject("htmlfile")
wWidth = HTM.parentWindow.screen.Width
wHeight = HTM.parentWindow.screen.Height
wscript.echo wWidth & "X" & wHeight
在此处运行 Windows 10 Pro。我正在使用一个简单的脚本作为 Windows 游戏控制器配置的快捷方式,但我总是必须手动导航到对话框中的“属性”按钮才能到达我真正想要到达的位置。这第一张图片是快捷方式将我带到的位置:
现在我想去的地方是可以通过按下“属性”按钮来实现的下一页:
我想更改脚本,使其自动转到游戏控制器配置对话框的第二页。有没有办法修改脚本,甚至写一个新的来完成这个?这是 .vbs 脚本(由名为 Tileconfiy 的程序生成,该程序允许将快捷方式固定到开始菜单):
Dim targetPath, targetArguments
targetPath = """C:\Windows\explorer.exe"""
targetArguments = "C:\Windows\System32\joy.cpl"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory = "C:\Windows\System32\"
WshShell.Run targetPath & " " & targetArguments, 1
WshShell.AppActivate("joy.cpl")
WshShell.SendKeys("{TAB}")
WshShell.SendKeys("{ENTER}")
游戏配置打开正常,但 TAB 和 ENTER 部分未执行。我在代码的最后一部分尝试了几种变体,包括以下内容:
WshShell.SendKeys("{TAB}")
WshShell.SendKeys("{ENTER}")
和
WshShell.SendKeys("{TAB}")
WshShell.SendKeys("{~}")
和
WScript.CreateObject("WScript.Shell").SendKeys("{TAB})";
WScript.CreateObject("WScript.Shell").SendKeys("~");
和
WScript.CreateObject("WScript.Shell").SendKeys("{TAB}";
WScript.CreateObject("WScript.Shell").SendKeys("ENTER");
这些似乎都没有使它起作用。
当你这样做...
Set WshShell = CreateObject("WScript.Shell")
Call WshShell.Run("psexec -u administrator -p pw1234 cmd /c ipconfig > C:\Output.txt", 2, True)
...您会在短时间内看到命令提示符窗口。
我一直在网上搜索,我已经尝试了我能想到的一切来隐藏/最小化这个窗口,但不幸的是没有成功。
真的没有办法在隐藏/最小化窗口中运行 psexec 吗?
PS:不幸的是Call WshShell.Run("psexec -u administrator -p pw1234 start /min cmd /c ipconfig > C:\Output.txt", 2, True)
不起作用(错误消息:PsExec 无法启动启动...)。
我知道该cscript "filename.VBS"
命令,但我想在批处理文件中运行 VBS 代码,因此我不必制作 VBS 文件来执行此操作。
这是我的 VBS 代码:
sub Loading
do while brw.busy
wscript.sleep 350
loop
end sub
query=inputbox("Please Enter What You Would Like To Search:","Multi-Engine Internet Searcher")
'down-Google
set brw=CreateObject("InternetExplorer.Application")
brw.navigate "https://www.google.ca/#q=" & (query)
brw.toolbar=false
brw.statusbar=true
brw.height=650
brw.width=950
brw.left=0
brw.top=0
brw.resizable=true
Call Loading
brw.visible=true
'up-google
'down-bing