Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Скрипт, меняющий значение строки в INI-файле
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander printer-friendly view
View previous topic :: View next topic  
Author Message
Batya



Joined: 15 Dec 2004
Posts: 2218
Location: Москва, Россия

Post (Separately) Posted: Tue May 11, 2010 14:09    Post subject: Reply with quote

Den_Klimov
Code:
'==========================================================
' Замена нескольких параметров в wincmd.ini и рестарт TC
'==========================================================
Option Explicit
Dim WSH, FSO, TCIniFile
Set WSH   = CreateObject("WScript.Shell")
Set FSO   = CreateObject("Scripting.FileSystemObject")
TCIniFile = WSH.ExpandEnvironmentStrings("%COMMANDER_INI%")

'Пример замены нескольких параметров
ChangeIni "DirBrackets=0"  , "DirBrackets=1"
ChangeIni "StartupScreen=0", "StartupScreen=1"

'Рестарт TC
RestartTotal

'Выход
Quit

Sub Quit
  Set WSH = Nothing
  Set FSO = Nothing
  WScript.Quit
End Sub

Sub ChangeIni(pStr1, pStr2)
  Dim Text
  Text = FSO.OpenTextFile(TCIniFile, 1).ReadAll
  Text = Replace(Text, pStr1, pStr2, 1, -1, 1)
  FSO.OpenTextFile(TCIniFile, 2).Write Text
End Sub

'(c) Volniy
Sub RestartTotal
  Dim TCS, TCexe, Timeout, QuitByTimeOut
  Set TCS = CreateObject("TCScript.Helper")
  TCexe = """" & TCS.TCPath & "\totalcmd.exe"""
  'Завершаем работу ТС
  TCS.SendCommand "cm_Exit", True

  'Ожидание завершения работы ТС
  Timeout = 3000 ' Сколько ждать выключения в мсек
  Do
     Timeout = Timeout - 100
     If Timeout < 0 Then QuitByTimeOut = True: Exit Do
     WScript.Sleep 100
  Loop While TCS.IsRunningTC

  'Запускаем новый экземпляр программы
  If Not QuitByTimeOut Then WSH.Run TCexe

  Set TCS = Nothing
End Sub


17.05.2010 - Исправлено. Убрано обращение к внешнему скрипту.
_________________
Нет, я не сплю. Я просто медленно моргаю.


Last edited by Batya on Mon May 17, 2010 09:30; edited 1 time in total
Back to top
View user's profile Send private message
Den_Klimov



Joined: 03 Nov 2006
Posts: 207
Location: Ukraine.Kiev

Post (Separately) Posted: Sun May 16, 2010 04:41    Post subject: Reply with quote

Batya
Спасибо. Smile
1. Const ChangeIniFile = """C:\Путь\к скрипту\замены текста.vbs""" Ещё раз для тупых, к чему именно этот путь?
2. Работать будет если в пути %COMMANDER_PATH% использовать?
Back to top
View user's profile Send private message
Volniy



Joined: 15 Dec 2004
Posts: 585
Location: Местный

Post (Separately) Posted: Sun May 16, 2010 13:41    Post subject: Reply with quote

Замена секции
Внимание: существующая в ини-файле секция переписывается полностью!
Code:
'==========================================================
' Замена секции в wincmd.ini и рестарт TC
'==========================================================
Option Explicit
Dim WSH, TCS
Set WSH = CreateObject("WScript.Shell")
Set TCS = CreateObject("TCScript.Helper")

' Примеры замены секции:
' 1) Записываемые данные - из другого ini-файла
TCS.INIWriteSection TCS.MainINI, "configuration2" ,TCS.INIReadSection("C:\some.ini","some_section")

' 2) Записываемые данные секции формируются на лету
TCS.INIWriteSection TCS.MainINI, "configuration3" ,"FirstPar=0" & Chr(0) & "SecondPar=1" & Chr(0) & "ThirdPar=-1" & Chr(0)

'Рестарт TC
RestartTotal
Set TCS = Nothing
Set WSH = Nothing
WScript.Quit

Sub RestartTotal
  Dim TCexe, Timeout, QuitByTimeOut
  TCexe = """" & TCS.TCPath & "\totalcmd.exe"""
  'Завершаем работу ТС
  TCS.SendCommand "cm_Exit", True

  'Ожидание завершения работы ТС
  Timeout = 3000 ' Сколько ждать выключения в мсек
  Do
     Timeout = Timeout - 100
     If Timeout < 0 Then QuitByTimeOut = True: Exit Do
     WScript.Sleep 100
  Loop While TCS.IsRunningTC

  'Запускаем новый экземпляр программы
  If Not QuitByTimeOut Then WSH.Run TCexe

End Sub
Back to top
View user's profile Send private message
Batya



Joined: 15 Dec 2004
Posts: 2218
Location: Москва, Россия

Post (Separately) Posted: Mon May 17, 2010 09:32    Post subject: Reply with quote

Den_Klimov wrote:
1. Const ChangeIniFile = """C:\Путь\к скрипту\замены текста.vbs""" Ещё раз для тупых, к чему именно этот путь?
2. Работать будет если в пути %COMMANDER_PATH% использовать?

Поскольку есть вопросы, решил упростить - убрал обращение к внешнему скрипту.
_________________
Нет, я не сплю. Я просто медленно моргаю.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander All times are GMT + 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group