1

おはようございます、

私が取り組んでいるプロジェクトにアプローチする方法を見つけようとしている問題があります...

基本的に何が起こっているかというと、テキスト ファイルに移動し、特定のテキスト文字列 (IE ColumnSeparator=Y) を探して、それを ColumnSeparator=N に変更する必要があります。
「ColumnSeparator=Y/N」が存在しない場合、テキストのセクションをファイルに追加するために、4 ~ 5 行のテキストを書き込む必要があります。追記で大丈夫です。

さて、これはトリッキーな部分です。私が編集しているこのファイルは、〜 850 台のマシンで使用されるプログラムのファイルの構成であり、すべてのファイルは少し異なり、Windows XP と Windows 7 によって、2 つの異なる場所にあります。
Windows 7 では次の場所にありますC:\AS400\s10138fd.wsが、Windows XP では次の場所にあります。C:\Program Files\IBM\Client Access\Emulator\Private\AS400.ws

何か案は??

ありがとう!!

編集する必要がある *.ws ファイル情報は次のとおりです。

[Profile]
ID=WS
Description=
Version=9
[Translation]
IBMDefaultView=Y
DefaultView=
IBMDefaultDBCS=Y
DefaultDBCS=
[Communication]
AutoConnect=Y
Link=telnet5250
Session=5250
ForceConfigPanel=N
[Telnet5250]
HostName=S10138fd
Security=Y
HostPortNumber=992
SSLClientAuthentication=Y
CertSelection=AUTOSELECT
AutoReconnect=Y
[5250]
HostCodePage=037-U
PrinterType=IBM3812
[Keyboard]
CuaKeyboard=2
Language=United-States
IBMDefaultKeyboard=N
DefaultKeyboard=C:\AS400\AS400.KMP
[LastExitView]
A=4 1335 -14 896 609 3 13 29 400 0 IBM3270� 37

追加する必要があります:

[Window]
ViewFlags=CE00
RuleLinePos=0 0
ColumnSeparator=N

新しいスクリプトは次のとおりです。

if exist "c:\as400\s10138fd.ws" (cd \as400)

copy s10138fd.ws temp.ws
echo [Window]>s10138fd.ws
echo ViewFlags=CE00>>s10138fd.ws
echo RuleLinePos=0 0>>s10138fd.ws
echo ColumnSeparator=N>>s10138fd.ws
type temp.ws >>s10138fd.ws
del temp.ws

) ELSE (cd\program files\ibm\client access\emulator\private)

copy as400.ws temp.ws
echo [Window]>as400.ws
echo ViewFlags=CE00>>as400.ws
echo RuleLinePos=0 0>>as400.ws
echo ColumnSeparator=N>>as400.ws
type temp.ws >>as400.ws
del temp.ws
)
pause
4

3 に答える 3

2

したがって、実際には、単純な INI ファイルをバッチ スクリプトで条件付きで更新したいだけです。

これを単一ファイルのソリューションにする必要があると思います。それ以外の場合(バッチスクリプトで)、おそらく次のようなものを使用したでしょう:

現在指定されているとおりに実行するために、次のハイブリッド(バッチ/JScript)を作成しました (
1 つのファイルを使用し、一時ファイルは使用しません)。

@if (0)==(1) REM BatchScript: 
:INIT
 @ECHO OFF & CLS
:MAIN
 cscript //NoLogo //E:JScript "%~f0"
 GOTO ENDBAT
:ENDBAT
 ECHO        Press any key to exit...&PAUSE>NUL
 GOTO :EOF
@end // JScript:

 var TRG = ['C:\\Program Files\\IBM\\Client Access\\Emulator\\Private\\AS400.ws',
            'C:\\AS400\\s10138fd.ws'
           ],
     rxp = /ColumnSeparator=[YN]/i,
     rep = 'ColumnSeparator=N',
     add = ['[Window]',
            'ViewFlags=CE00',
            'RuleLinePos=0 0',
            'ColumnSeparator=N',
            ''  //empty line
           ].join('\r\n'),

     WSO = WScript.stdout,
     FSO = WScript.CreateObject("Scripting.FileSystemObject"),
                                 ForReading=1, ForWriting=2,
       L = TRG.length, ret = '', flg = 1, HND;


 while(L--){
    if( FSO.FileExists(TRG[L]) ){ TRG = TRG[L]; L = ''; break; }
 } 

 if(L === ''){
    WSO.write('FOUND: '+TRG+'\r\nWorking...\r\n');
    HND=FSO.OpenTextFile(TRG, ForReading);
    while(!HND.AtEndOfStream){
       L=HND.ReadLine();
       if( rxp.test(L) ){ L = L.replace(rxp,rep); flg = 0; }
       ret+= L+'\r\n';
    }  HND.Close();

    if(flg){ ret= ret.replace(/(\r\n)*$/,'\r\n')+add; }

    HND=FSO.OpenTextFile(TRG, ForWriting);
    HND.Write(ret);  HND.Close();

    WSO.write('\r\nDONE!!!\r\n');
 } else {
    WSO.write('ERROR: no file found\r\n');
 }
 

ノート:

  • スクリプトの最後に空行があることを忘れずに (確実に)、' yourExtCommand.bat' という名前を付けてください。
  • このスクリプトは、W98、W2k、XP/2003、Vista、および Windows 7 (まだ 8 ではありませんが、とにかくそれを使用している..) で (JSLint を含めて) 徹底的にテストされており、魅力的に機能します!

  • このスクリプトは、次のように指定したため、ini ファイル自体の場所を「os-detection」として使用します。 Files\IBM\Client Access\Emulator\Private\AS400.ws '
    そして、検出した最初のファイル (システム上で唯一のファイルである必要があります)を win7 で開始して更新します ('巧妙に' 保護されたファイルへの不要なアクセスを回避します) %programfiles% dir と UAC のトリガー) .
  • また、「ColumnSeparator=N」を「ColumnSeparator=N」に変更しても問題はありませんか?
    ' If "ColumnSeparator=Y/N" is not exist, I need to write ~4-5 lines of text to add the section of the text to the file . ', '追加ファイルの末尾まで' および '特定のテキスト文字列 (IE ColumnSeparator=Y) を探し、それを ColumnSeparator=N に変更します'
  • ...Press any key to...無人で実行するには、行全体を REM/delete します。
  • add後続の空白行をスマートに処理するようにスクリプトを更新し、変数を介してそれらを制御できるようにしました。
  • 追加されたセクションの前に空白行が必要な場合は、行  add = ['[Window]',
    を  次のように変更しますadd = ['', '[Window]',(たとえば)

最後に、ファイルを使用してiniファイルを更新/変更 できるように見えることに注意してください(部分的には私自身のために) :inf

  • RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 c:\temp\test.inf    (「より良い」と言われていますか?)

また

  • RUNDLL32 SETUPX.DLL,LaunchHinfSection DefaultInstall 132 test.inf

(どちらもバッチ スクリプトから呼び出されます)。

inf ファイルは、バッチスクリプト / JScript / VBScript からエコーまたは書き込みすることもできます。

これらの inf ファイルは次のようになります。

[version]
signature="$CHICAGO$"


[DefaultInstall]
UpdateInis=IniVal


[IniVal]
"C:\temp\whatever.ini",YourSection,"Something=OldValue","Something=NewValue",0

また:

[Version]
Signature="$CHICAGO$"

[DefaultInstall]
UpdateINIs=Sys.Ini

[Sys.Ini]
System.ini,ReplaceMeWithAppropriateSection,,”MinPs=32”

幸運を!

于 2013-04-04T05:38:58.563 に答える
0

これが私が動作させることができた新しいスクリプトです!!!

c:
cd \as400
SETLOCAL EnableDelayedExpansion
for /f "tokens=*" %%x in ('dir /b/s/a-d *.ws') do ( 
copy %%x temp.txt
del %%x
Echo [Window]>%%x
Echo ViewFlags=CE00>>%%x
Echo RuleLinePos=0 0 >>%%x
Echo ColumnSeparator=N>>%%x
type temp.txt>>%%x
del temp.txt
)
else (
c:
cd \users
SETLOCAL EnableDelayedExpansion
for /f "tokens=*" %%x in ('dir /b/s/a-d *.ws') do ( 
copy %%x temp.txt
del %%x
Echo [Window]>%%x
Echo ViewFlags=CE00>>%%x
Echo RuleLinePos=0 0 >>%%x
Echo ColumnSeparator=N>>%%x
type temp.txt>>%%x
)
else (
c:
cd \"Documents and Settings"
SETLOCAL EnableDelayedExpansion
for /f "tokens=*" %%x in ('dir /b/s/a-d *.ws') do ( 
copy %%x temp.txt
del %%x
Echo [Window]>%%x
Echo ViewFlags=CE00>>%%x
Echo RuleLinePos=0 0 >>%%x
Echo ColumnSeparator=N>>%%x
type temp.txt>>%%x
del temp.txt
)
于 2013-04-08T19:20:01.267 に答える