2

私のバッチ ファイルでは、VBScript を呼び出して 3 つのパラメーターを渡しています。以下に示すように、パラメーターは「IPADDRESS」、「PicName」、および「Storage」です。

バッチファイル:

        set Pathname="C:\User\username\locationOfFile 
        cd /d %Pathname%
        cscript.exe C:\User\username\locationOfFile\myScript.vbs IPADDRESS PicName Storage

私の VB6 プログラムでは、パラメーター値が定義されています。

たとえば、IPADDRESS = "170.190.xxx.xxx" としましょう

バッチ ファイルを読み取って、VB6 フォーム内の宣言に基づいて IPADDRESS の値を使用する方法はありますか? 変数 IPADDRESS、PicName、および Storage は、VB6 プログラムが通信する外部アプリケーションに基づいて常に変化するため、バッチで静的に設定することはできません ( ....\myScript.vbs 170.190.xxx.xxx pic1 C:\保管所)

私のVBScriptは以下のとおりです。

   Option explicit

   if WScript.Arguments.Count <> 3 then
      WScript.Echo "Missing parameters"
   else

   Dim imageMagick
   Set imageMagick = CreateObject("ImageMagickObject.MagickImage.1")

   Dim cam_add 
   Dim annotate 
   Dim filename 
   Dim cmd
   Dim WshShell
   Dim return

   cam_add = """http://" & WScript.Arguments(0) &"/image"""
   annotate = """" & WScript.Arguments(1) & " - """ '& Date
   filename = """" & WScript.Arguments(2) & WScript.Arguments(1) & ".jpg"""
   cmd = "convert " & cam_add & " -fill gold -pointsize 45 -gravity southwest -annotate         0x0+25+25 " & annotate & " -trim +repage -verbose " & filename

   WScript.Echo cmd

   Set WshShell = WScript.CreateObject("WScript.Shell")

   WshShell.CurrentDirectory = "C:\Program Files\ImageMagick-6.8.0-Q16\"

   return = WshShell.Run(cmd) 


   end if

要約すると、バッチを次のように設定する必要があります。

cscript.exe C:\User\username\locationOfFile\myScript.vbs IPADDRESS PicName ストレージ

そのため、パラメータ値は、VB6 フォーム内で設定されている内容に従って使用できます。

4

2 に答える 2

2

次の場合:

shell "the.bat " & IPADDRESS & " " & PicName & " " & Storage

次にthe.bat、スペースで区切られた各引数内で、序数%Nである where is を介して使用できます。Nso%1には の値が含まれ、 の値がIPADDRESS含ま%2PicNameます。

その後、VBScript に転送するには:

cscript.exe C:\User\username\locationOfFile\myScript.vbs %1 %2 %3

(いずれかの変数にスペースが含まれている場合は、bat ファイルに渡す前にそれらを「引用」する必要があります)

(おそらくchdir(..)VB6でCScriptを直接実行することもできます)

于 2012-12-20T13:14:38.117 に答える
1

とにかく、この単純なものにはバッチファイルは必要ありません。結局のところ、操作するスクリプト全体があります。

そこから CD を設定することも、VB6 プログラムで次のように設定することもできます。

Option Explicit

Private Sub Main()
    Dim CD As String
    Dim IPADDRESS  As String
    Dim PicName As String
    Dim Storage As String
    Dim OrigCD As String

    CD = "D:\Photo Archives"
    IPADDRESS = "127.0.0.1"
    PicName = "Fudd"
    Storage = "C:\Storage"

    'Cache CD so we can restore it.
    'Change CD and drive so it is inherited.
    OrigCD = CurDir$()
    ChDir CD
    ChDrive CD

    Shell "cscript """ _
        & App.Path & "\test.vbs "" """ _
        & IPADDRESS & """ """ _
        & PicName & """ """ _
        & Storage & """", _
          vbNormalFocus

    'Restore CD and drive.
    ChDir OrigCD
    ChDrive OrigCD

    'Rest of program.
End Sub

スクリプトのサンプル:

Option Explicit

Private CD

Private Sub Msg(ByVal Text)
    With WScript
        .StdOut.WriteLine Text
        .StdOut.Write "Press ENTER to continue..."
        .StdIn.ReadLine
    End With
End Sub

If WScript.Arguments.Count <> 3 Then
    Msg "Missing parameters"
    WScript.Quit
End If

'Show the CD and the arguments.
With CreateObject("WScript.Shell")
    CD = .CurrentDirectory
End With
With WScript.Arguments
    Msg CD & vbNewLine _
      & """" & .Item(0) _
      & """ """ & .Item(1) _
      & """ """ & .Item(2) & """"
End With

しかし、スクリプトが必要なようにも見えません。コマンドをビルドし、CD/ドライブを設定し、ビルドされたコマンド文字列をすべて VB6 プログラム内から Shell() できます。

于 2012-12-21T00:41:04.217 に答える