AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题

问题[vbscript](computer)

Martin Hope
kaj
Asked: 2024-10-16 11:17:41 +0800 CST

我希望这个脚本能够与“文件和文件夹”一起使用,并避免弹出窗口

  • 3
//  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);
    }
}
vbscript
  • 1 个回答
  • 78 Views
Martin Hope
VB88
Asked: 2022-04-21 07:15:52 +0800 CST

创建后打开文本文件

  • 5

请帮助查看文件创建成功后无法打开查看的问题所在。

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
  • 1 个回答
  • 87 Views
Martin Hope
A__
Asked: 2021-01-16 12:10:11 +0800 CST

使用 VBS 专注于特定进程,无需进程标题或 PID

  • 5

我有一个 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 的新手。谢谢你的帮助!

windows vbscript
  • 1 个回答
  • 779 Views
Martin Hope
Coding Newbie
Asked: 2020-11-18 04:04:40 +0800 CST

如何将源文件夹名称附加到复制到 vbs 中另一个位置的文件?

  • 6

我有一个包含很多子文件夹的文件夹“文档”。这些子文件夹下有文件。

我的目标是将文件移动到一个文件夹位置,然后在某个时候能够将它们移回它们来自的子文件夹。

我的一般想法是在移动后将子文件夹名称附加到文件的开头。然后在需要将它们移回其源子文件夹时,可以将其用作参考。

这是可行的,还是您对我如何实现这一目标有任何其他想法?我只知道如何在 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
vbscript
  • 1 个回答
  • 73 Views
Martin Hope
frankell
Asked: 2020-11-08 08:33:46 +0800 CST

如何获取屏幕分辨率并将其保存到文本文件?

  • 6

我找到了以下 vbs 脚本来获取屏幕分辨率

但我想将结果保存在文本文件中,请帮助我

    Dim HTM, wWidth, wHeight
    Set HTM = CreateObject("htmlfile")
    wWidth = HTM.parentWindow.screen.Width
    wHeight = HTM.parentWindow.screen.Height
    wscript.echo wWidth & "X" & wHeight
vbscript screenresolution
  • 1 个回答
  • 429 Views
Martin Hope
Kalamalka Kid
Asked: 2020-07-12 12:39:16 +0800 CST

打开对话框的命令

  • 7

在此处运行 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");

这些似乎都没有使它起作用。

script vbscript
  • 1 个回答
  • 204 Views
Martin Hope
Seeky
Asked: 2020-06-04 05:04:36 +0800 CST

如何从 VB 脚本 (VBS) 最小化运行 psexec

  • 7

当你这样做...

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 无法启动启动...)。

vbscript psexec
  • 2 个回答
  • 868 Views
Martin Hope
Vakors 3000
Asked: 2019-12-24 21:54:46 +0800 CST

如何在批处理文件中运行 VBS 代码?

  • 7

我知道该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
batch vbscript
  • 1 个回答
  • 8215 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve