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
    • 最新
    • 标签
主页 / user-905681

Mastaxx's questions

Martin Hope
Mastaxx
Asked: 2023-01-24 10:22:09 +0800 CST

尝试在 powershell 中对 tracert 的输出进行颜色编码 - 未按预期工作

  • 6

我正在尝试根据以毫秒为单位的延迟在 powershell 中将线条着色为绿色、黄色和红色。我们的远程工作流规定任何超过 40 毫秒的东西都是不好的,所以我希望将其直观地呈现给运行测试的人,并将其打包为 exe,供他们在需要时下载和运行。

  • 1-19ms = 绿色
  • 20-39ms = 黄色
  • 40-500 毫秒 = 红色
  • “请求超时”=红色

但是,当我尝试在 ISE 中记录它时,它似乎没有按预期运行。它通常只为所有线路返回一种纯色,有时它会在跟踪路由测试中完全错过一些线路。我特意选择了一个随机的澳大利亚 IP 地址来运行测试,因为它距离很远,并且随着跃点的继续,应该会提供低延迟到高延迟的良好组合。

谁能建议我可能哪里出错了?

$traceroute = tracert 47.74.90.56

foreach ($trace in $traceroute)
{
if ($trace -Match '[1-9] ms' )
{
write-host "$trace" -ForegroundColor green
}
elseif ($trace -Match 'request timed out' )
{
write-host "$trace" -ForegroundColor red
}
elseif ($trace -Match '[1-0][1-9] ms' )
{
write-host "$trace" -ForegroundColor green
}
elseif ($trace -Match '[2-3][0-9] ms' )
{
write-host "$trace" -ForegroundColor yellow
}
elseif ($trace -Match '[4-9][0-9] ms' )
{
write-host "$trace" -ForegroundColor red
}
elseif ($trace -Match '[1-9][0-9][0-9] ms' )
{
write-host "$trace" -ForegroundColor red
}
}
windows-10
  • 2 个回答
  • 25 Views
Martin Hope
Mastaxx
Asked: 2022-06-24 03:47:22 +0800 CST

如何为 C:/Users 中的每个用户名在 get-content 命令上返回真/假?

  • 7

我们希望从每个用户的 appdata 文件夹中消除我们已经识别(并且也有手动修复)的错误配置文件的存在。配置文件只存在于这里和那里,而不是每个用户中。所以我试图拼凑一个脚本,如果指定的文本与 config.xml 上的 get-content 匹配,它将返回 true/false。我想对每台机器上的每个用户配置文件运行它并将结果输出到 csv。

到目前为止,我遇到了一个问题。仍在学习 powershell,因此非常感谢任何帮助。

$Users = "C:\Users"
$x = "This is the text I'm looking for"


Foreach ($Username in $Users)

{
$Path = "$Users\$Username\AppData\Local\MyApp\Settings\Config.xml"
$y = Get-Content -Path $Path
If ($y -match $x)

{
    "true"

}
else 
{
    "false"
}
}

如您所见,我还没有进入 csv 部分,因为我无法获得为获取内容生成的正确路径。

而不是拥有我希望的正确路径,因为 foreach 循环工作它的方式是:

"C:\Users\Username1\AppData\Local\MyApp\Settings\Config.xml"
"C:\Users\Username2\AppData\Local\MyApp\Settings\Config.xml"
"C:\Users\Username3\AppData\Local\MyApp\Settings\Config.xml"

相反,我收到以下错误:

Get-Content : Cannot find path 'C:\Users\C:\Users\AppData\Local\MyApp\Settings\Config.xml' because it does not exist.
At C:\Users\mastaxx\Desktop\test.ps1:9 char:6
+ $y = Get-Content -Path $Path
+      ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\C:\Use...ings\Config.xml:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

我在这里看似愚蠢的假设是 $Users 会是"C:\Users"(我相信这是因为我已经定义了它)并且 $Username 会是"Username1"(显然不是)。相反,我可以看到它也在"C:\Users"这种情况下,使得正在构建的路径是不正确的:

C:\Users\C:\Users\AppData\Local\MyApp\Settings\Config.xml

我希望 foreach 循环将内部的每个文件夹$Users视为一个单独的对象并成为$Username每个循环实例中的,允许我将其插入到配置文件中$path,如下所示:

$Users   $Username
  ↓          ↓
C:\Users\Username1\AppData\Local\MyApp\Settings\Config.xml

我不完全确定我做错了什么,但我知道我肯定在这里做一些愚蠢的事情。非常感谢任何具有更好 PS 技能的人帮助指出这一点?

powershell command-line
  • 1 个回答
  • 203 Views
Martin Hope
Mastaxx
Asked: 2022-04-20 04:37:40 +0800 CST

如何批量删除 CSV 文件中不以正斜杠结尾的整行?

  • 5

我有一个太大的 CSV 文件,因为它包含文件路径和目录路径。我需要对其进行修改,使其仅显示目录路径而不显示文件本身。

我想知道创建一个“拖放”批处理脚本是否会更直接单元格的末端,所以这是唯一要使用的公分母。

Desired action:
If end with forward slash = keep row
If not end with forward slash = delete entire row

在此处输入图像描述

microsoft-excel batch
  • 4 个回答
  • 604 Views
Martin Hope
Mastaxx
Asked: 2021-08-14 00:02:05 +0800 CST

当我尝试让我的脚本针对结果中的每个单独的字符串运行时,我的 foreach 哪里出了问题?

  • 5

我有一个 Users.log 文件,其中列出了与从 AD 中提取的用户名、组成员身份和分配的服务器路径有关的以下信息:

RandomUser01,RandomGroup01_654321_098765,\\server\data\designs\RandomArea01_654321_098765\data_store
RandomUser02,RandomGroup02_654321_098765,\\server\data\designs\RandomArea02_654321_098765\data_store
RandomUser03,RandomGroup03_654321_098765,\\server\data\designs\RandomArea03_654321_098765\data_store
RandomUser04,RandomGroup04_654321_098765,\\server\data\designs\RandomArea04_654321_098765\data_store
MyUsername,MyGroup01_654321_098765,\\server\data\designs\MyArea01_654321_098765\data_store
MyUsername,MyGroup02_654321_098765,\\server\data\designs\Myrea02_654321_098765\data_store

该脚本旨在首先检查是否已存在任何包含“数据”一词的快捷方式,然后隔离包含我的用户名 ( Select-String $env:username) 的 users.log 文件中的字符串,将结果过滤到仅 UNC 服务器路径 ( $ServerPath = $Object -replace ”[^,]*,”,””),然后使用它来创建服务器的唯一桌面快捷方式。它还设置为使用组名作为快捷方式名称 ( $ShortcutName = $ProjectName.Substring(0, $ProjectName.IndexOf('_')))

脚本:

function Set-ShortCut {
    Param ( 
        [string]$SourceLnk, 
        [string]$DestinationPath 
    )
        
        $WshShell = New-Object -comObject WScript.Shell
        $Shortcut = $WshShell.CreateShortcut($SourceLnk)
        $Shortcut.TargetPath = $DestinationPath
        $Shortcut.Save()

}

$WantFile = "$env:USERPROFILE\Desktop\data*.lnk"
$FileExists = Test-Path $WantFile
$FindUser = Get-Content \\Server\data\logs\Users.log | Select-String $env:username



If ($FileExists -eq $False)


{

Write-Host "Conditions have been satisfied. Running script to create data_store shortcut"
Start-Sleep -Seconds 5


foreach ($Object in $FindUser) 
{
$ProjectName = $finduser -split ",", 3 | Select-Object -Index 1 
$ShortcutName = $ProjectName.Substring(0, $ProjectName.IndexOf('_'))
$ServerPath = $Object -replace ”[^,]*,”,””
$SourcePath = "$ServerPath"
$ProjectName
$ShortcutName
$ServerPath
$SourcePath
Set-ShortCut -SourceLnk "$env:USERPROFILE\Desktop\$ShortcutName data_store.lnk" -DestinationPath $SourcePath
}




}

Else {

Start-Sleep -Seconds 5
Write-Host "The Script will now EXIT..."
Start-Sleep -Seconds 5
Exit
}

我希望脚本为在结果中找到的每个字符串$FindUser运行一次。这就是我使用foreach ($Object in $FindUser). 但我无法让脚本执行此操作。

在这个 users.log 文件示例中,当我运行$FindUser它时会产生两个结果:

MyUsername,MyGroup01_654321_098765,\\server\data\designs\MyArea01_654321_098765\data_store
MyUsername,MyGroup02_654321_098765,\\server\data\designs\Myrea02_654321_098765\data_store

但是,我认为我在使用foreach. 我也试过ForEach-Object了,没有运气。有没有人有什么建议?我需要脚本单独针对每个字符串运行$FindUsers。目前它只对所有结果$FindUsers集中运行一次。

windows-10 powershell
  • 1 个回答
  • 52 Views
Martin Hope
Mastaxx
Asked: 2021-08-04 11:29:15 +0800 CST

如何将这些结果中的文本解析为单独脚本的参数?

  • 7

我需要从运行命令时得到的结果中提取client_TargetText和提取:AnotherTargetText_110953_140521whoami /groups

Powershell 结果:

Group Name                                 Type             SID                                           Attributes
========================================== ================ ============================================= ==================================================
Everyone                                   Well-known group S-1-1-0                                       Mandatory group, Enabled by default, Enabled group
BUILTIN\Users                              Alias            S-1-5-32-545                                  Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4                                       Mandatory group, Enabled by default, Enabled group
CONSOLE LOGON                              Well-known group S-1-2-1                                       Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11                                      Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\This Organization             Well-known group S-1-5-15                                      Mandatory group, Enabled by default, Enabled group
LOCAL                                      Well-known group S-1-2-0                                       Mandatory group, Enabled by default, Enabled group
MYDOMAIN\GGM-FIRE-PC                       Group            S-1-5-21-457414007-2867176591-488352320-6061  Mandatory group, Enabled by default, Enabled group
MYDOMAIN\myles_gp                          Group            S-1-5-21-457414007-2867176591-488352320-12531 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\GGM-RDP                           Group            S-1-5-21-457414007-2867176591-488352320-13873 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\client_TargetText                 Group            S-1-5-21-457414007-2867176591-488352320-7924  Mandatory group, Enabled by default, Enabled group
MYDOMAIN\AnotherTargetText_110953_140521   Group            S-1-5-21-457414007-2867176591-488352320-13947 Mandatory group, Enabled by default, Enabled group
Authentication authority asserted identity Well-known group S-1-18-1                                      Mandatory group, Enabled by default, Enabled group
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192
PS C:\Users\test.dev>

我将如何去抓取client_TargetText和删除client_它,让它变得公正TargetText,然后$Param1在下面的脚本中制作它?(client_总是出现在我需要为 $Param1 抓取的文本中)

那么我将如何去抓取AnotherTargetText_110953_140521以便可以$Param2在下面的脚本中制作它?(在这些 AD 组中,所需的文本$Param2始终以 为后缀)6digits_6digits

我的目标是以某种方式将此文本发送到我用于在用户桌面上创建服务器快捷方式的脚本中。

运行时每个用户的结果会有所不同,whoami所以我认为唯一可以使用的通配符是client_and 6digits_6digits。任何帮助我找到这个答案的人都非常感谢,因为我正在尝试了解这将如何工作但无法弄清楚。

下面的脚本是成功解析这两条文本并将它们转换为$Param1and后的预期结果$Param2:

function set-shortcut {
param ( [string]$SourceLnk, [string]$DestinationPath )
    $WshShell = New-Object -comObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut($SourceLnk)
    $Shortcut.TargetPath = $DestinationPath
    $Shortcut.Save()
    }

    try{

$Param1 = TargetText
$Param2 = AnotherTargetText_110953_140521
$SourcePath = \\server\data\designs\$Param1\$Param2\data_store"

set-shortcut "%USERPROFILE%\Desktop\data_store.lnk" "$SourcePath"

     "This worked"
     
pause
}

catch
   {
    
    "This didn't work"
}
pause
windows-10 powershell
  • 1 个回答
  • 146 Views
Martin Hope
Mastaxx
Asked: 2020-07-20 03:35:07 +0800 CST

为什么这个 New-Item 命令在 powershell 中有效,但在 ps1 脚本中无效?

  • 3

完全被困在这里,不知道该怎么做:我有一个多选交互式 Powershell 脚本,我正在为操作组合在一起,所以只要他们想在远程计算机上执行快速任务,他们就会节省几分钟。

我已经用 just 替换了所有其他选项的所有代码You have selected #,所以我不会让任何人对其余的脚本内容感到厌烦,但是选择6让我发疯。

这就是我的目标,但还不能超越第一个要点:

  • 创建新.vnc文件
  • 将文本的标准 VNC 协议正文添加到文件中
  • $ComputerName之后添加Host=
  • 启动文件

问题是下面根本不会创建文件;如果直接复制/粘贴到 Powershell 中,它可以工作,但它不会在脚本中运行!有谁知道为什么会这样?

$commands = {
  function Show-Menu
  {
    param (
      [string]$Title = 'My Menu'
    )
    Clear-Host
    Write-Host "================ $Title ================"

    Write-Host "1: Press '1' (Description)."
    Write-Host "2: Press '2' (Description)."
    Write-Host "3: Press '3' (Description)."
    Write-Host "4: Press '4' (Description)."
    Write-Host "5: Press '5' (Description)."
    Write-Host "6: Press '6' To start a VNC Connection."
    Write-Host "Q: Press 'Q' to quit."
  }

  Show-Menu –Title 'My Menu'
  $selection = Read-Host "Please make a selection"
  switch ($selection)
  {
    '1' {
      "You have selected 1"
      sleep -seconds 2
    } '2' {
      "You have selected 2"
      sleep -seconds 2
    } '3' {
      "You have selected 3"
      sleep -seconds 2
    } '4' {
      "You have selected 4"
      sleep -seconds 2
    } '5' {
      "You have selected 5"
      sleep -seconds 2
    } '6' {
      $ComputerName = (Read-Host "ComputerName")
      {
        New-Item -Path "C:\Windows\Temp\$ComputerName.VNC"
        Set-Content "C:\Windows\Temp\$ComputerName.VNC" '
        [connection]
        host=$ComputerName
        port=5900
        [options]
        use_encoding_1=1
        copyrect=1
        viewonly=0
        fullscreen=0
        8bit=0
        shared=1
        belldeiconify=0
        disableclipboard=0
        swapmouse=0
        fitwindow=0
        cursorshape=1
        noremotecursor=0
        preferred_encoding=7
        compresslevel=-1
        quality=6
        localcursor=1
        scale_den=1
        scale_num=1
        local_cursor_shape=1'
      }
    } 'q' {
      #Closes the script
      return
    }
  }
  .$commands

}
&$commands
windows-10 powershell
  • 2 个回答
  • 526 Views
Martin Hope
Mastaxx
Asked: 2019-05-21 04:54:52 +0800 CST

AutoHotKey:如何设置当前循环迭代的起始值?

  • 5

我制作了一个基本的 AHK 脚本,它为我每天使用的系统上的每个文件添加了唯一的元数据。我的想法是将 _01 添加到第一个文件,然后将 _02 添加到第二个文件,然后一直上升,直到我退出脚本。

起初,我觉得我已经做了很长一段时间,我不确定需要什么才能让脚本更小,编辑起来更轻松。

这是脚本:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
F3::

 {
    Send, {LAlt}
    Sleep, 20
    Send, {Right}
    Sleep, 200
    Send, {Right}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 107, 30
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 346, 38
    Sleep, 200
    Send, ^v
    Sleep, 100
    Send, _01
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    MouseClick, Left, 91, 102
    Sleep, 100
    MouseClick, Left, 92, 100
    Sleep, 100
    MouseClick, Left, 147, 156
    Sleep, 100
    Send, {Down}



    Send, {LAlt}
    Sleep, 20
    Send, {Right}
    Sleep, 200
    Send, {Right}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 107, 30
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 346, 38
    Sleep, 200
    Send, ^v
    Sleep, 100
    Send, _02
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    MouseClick, Left, 91, 102
    Sleep, 100
    MouseClick, Left, 92, 100
    Sleep, 100
    MouseClick, Left, 147, 156
    Sleep, 100
    Send, {Down}



    Send, {LAlt}
    Sleep, 20
    Send, {Right}
    Sleep, 200
    Send, {Right}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 107, 30
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 346, 38
    Sleep, 200
    Send, ^v
    Sleep, 100
    Send, _03
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    MouseClick, Left, 91, 102
    Sleep, 100
    MouseClick, Left, 92, 100
    Sleep, 100
    MouseClick, Left, 147, 156
    Sleep, 100
    Send, {Down}



    Send, {LAlt}
    Sleep, 20
    Send, {Right}
    Sleep, 200
    Send, {Right}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 107, 30
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 346, 38
    Sleep, 200
    Send, ^v
    Sleep, 100
    Send, _04
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    MouseClick, Left, 91, 102
    Sleep, 100
    MouseClick, Left, 92, 100
    Sleep, 100
    MouseClick, Left, 147, 156
    Sleep, 100
    Send, {Down}



    Send, {LAlt}
    Sleep, 20
    Send, {Right}
    Sleep, 200
    Send, {Right}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 107, 30
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 346, 38
    Sleep, 200
    Send, ^v
    Sleep, 100
    Send, _05
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    MouseClick, Left, 91, 102
    Sleep, 100
    MouseClick, Left, 92, 100
    Sleep, 100
    MouseClick, Left, 147, 156
    Sleep, 100
    Send, {Down}

 }

如您所见,我不得不复制/粘贴整个脚本,并在下一部分中将 _01 更改为 _02,然后是 _03、_04 和 _05。

我发现了如何使用Loop + A_index来做到这一点,它工作正常,就像上面的一样:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
F3::

Loop, 5

 {
    Send, {LAlt}
    Sleep, 20
    Send, {Right}
    Sleep, 200
    Send, {Right}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Right}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 107, 30
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Down}
    Sleep, 20
    Send, {Enter}
    Sleep, 100
    MouseClick, Left, 346, 38
    Sleep, 200
    Send, ^v
    Sleep, 100
    Send, _
    Sleep, 100
    Send %A_Index%
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    Send, {Enter}
    Sleep, 200
    MouseClick, Left, 91, 102
    Sleep, 100
    MouseClick, Left, 92, 100
    Sleep, 100
    MouseClick, Left, 147, 156
    Sleep, 100
    Send, {Down}


}

I now need to be able to set the starting value of %A_index% with the use of a input box at the beginning of the script.

I want to be able to enter any number into the inputbox and have %A_index% work sequentially starting from that number.

So since A_Index simply keeps track of the current loop iteration, and therefore is a built-in internal value that cannot be changed...

...what i'm essentially asking is:

How do I get the script to start from a specific loop iteration using inputbox?

Does anyone know how this can be achieved?

windows-7 script
  • 1 个回答
  • 309 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