This is my function to remove the directory after uninstalling.
Basically, in my .ism file, there are 2 .rul files(setup.rul and VerGetFileProperty.rul). I have added some code to clean the directory in setup.rul. I build, and one setup.exe is formed. While I run setup.exe, it will ask me to select the db, if I select a db, its says the db server is not found. But if I run the original setup, it will auto detect db server and install. How is the setup.exe getting created? I haven't made any changes on searching for db server part. I have just created a function to remove the directory while uninstalling.
function fnClean()
NUMBER nrv;
begin
if (ExistsDir (INSTALLDIR ^ "XYZ Dir") = EXISTS) then
SetDialogTitle(DLG_ASK_YESNO,"Delete Logs");
nrv = AskYesNo( "Do you want to delete all log files now? Say No if you prefer delete them later manually.", YES );
if ( nrv ) then
nrv = DeleteDir (INSTALLDIR ^ "XYZ Dir", ALLCONTENTS);
DeleteDir (INSTALLDIR, ALLCONTENTS);
endif;
else
DeleteDir (INSTALLDIR, ALLCONTENTS);
endif;
end;
I assume your installer either calling some exe that is generating the log files, or the log files are generated by using whatever application you are installing.
If you are using an MSI(Windows Installer) based project, you can add the files to the RemoveFile table. You'll want to use a InstallMode of 2 (remove on uninstall)
editing to expand answer
cmd_line = "cmd /c """ & objNamedArgs.Item("SQLCMD") & """ " & objNamedArgs.Item("CONNECT") & _" -i " & sql_file & " > " & log_file & " 2>&1"
-i "sqlfile" is an argument to the sqlcmd program. -i means "input" and the sqlfile will be whatever is being specified, usually a .sql script.
logfile means: redirect output of whatever command (in this case, sqlcmd) into the file specified by logfile.
The 2>&1 is already answered here.
Related
I have the following automator apple script that I'm using so that when I drag a file into a dock icon, it opens that file in vim:
on run {input, parameters}
set filename to POSIX path of input
set cmd to "clear && 'vim' '" & filename & "' && exit"
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text cmd
end tell
end tell
end run
However, I would also like to allow clicking the icon itself to open vim without any file, i.e., running $ vim. How would I change the above script so that:
If a filename is passed, I open vim with that file, vim filename
If no filename is passed (the icon is just double-clicked), it just opens vim, with vim ?
The following example AppleScript code will do as you've asked; however, keep in mind that input is a list and as presently coded it is expecting a single item list, meaning you've only dragged and dropped one file onto the app's Dock Tile:
on run {input, parameters}
if not input is equal to {} then
set filename to POSIX path of first item of input
set cmd to "clear && 'vim' '" & filename & "' && exit"
else
set cmd to "clear && 'vim' '" & "' && exit"
end if
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text cmd
end tell
end tell
end run
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.
I am running into a problem automating an installation procedure. I want to install a program, and then patch it with a custom UserPatch to remove some glitches.
The UserPatch executable must be run from the installation directory, so I must retrieve this address from the installer. Then, after the program is installed, the script must copy the UserPatch file to the installation directory, and run it from there.
I retrieve the pathname as shown below. The script copies the raw text from the window, which I strip down to just the line containing the pathname.
WinActivate("Dir browse box title")
$InstallDir = WinGetText("Dir browse box title")
$split = StringSplit( $InstallDir, "&Path", 1)
$InstallDir = $split[2]
$split = StringSplit( $InstallDir, "&OK", 1)
$InstallDir = $split[1]
ControlClick("Dir browse box title", "&Drives", "[Class:CButtonClassName; INSTANCE:2]")
Sleep(100)
When printing "$InstallDir" after the above procedure, it shows exactly what I want it to be: "C:\Program Files (x86)\Path to\Installation folder" (without '"').
The problem is this: It doesn't copy the file when I run the code snippet below. It does work when I hardcode the pathname (commented in the code below), but not when using the $InstallDir variable as retrieved by the code snippet above.
; Install the UserPatch
; $InstallDir = "C:\Program Files (x86)\Path to\Installation folder"
$UserPatchName = "SetupAoC.exe"
FileCopy($UserPatchName, $InstallDir & "\" & $UserPatchName)
Run($InstallDir & "\" & $UserPatchName)
WinWait("SetupAoC - Feature Update Tool")
ControlClick("SetupAoC - Feature Update Tool", "Install", "[Class:DirectUIHWND; INSTANCE:1]")
Send("{SPACE}")
Sleep(2000)
WinClose ("SetupAoC - Install Complete")
WinClose ("SetupAoC - Feature Update Tool")
I've got the feeling that I'm missing something obvious, but I really can't tell what the problem is? Any ideas?
Thanks in advance!
EDIT in reply to comments:
After
$InstallDir = WinGetText("Dir browse box title")
the value of $InstallDir is
&Drives
C:\ Crucial M500
&Folders
&Path
C:\Program Files (x86)\Path to\Installation folder
&OK
&Cancel
I then use StringSplit, which creates an array of strings, separated by the specified delimiter.
OK, problem eliminated.
The problem was that my "C:\path...." string was preceded and trailed by two #CRLF characters (new lines). These were also present in the raw data that I copied from the window, as I didn't include them in my delimiters.
I didn't notice them when printing the output, as they're white-space. I found out when writing the $InstallDir variable to a file, in a desperate attempt.
Anyway, Solved with
$InstallDir = StringReplace($InstallDir, #CRLF, "")
Thanks for the tips, #Matrix and #McBarby!
I am able to download files from SFTP in CMD window, by using following code:
WinSCP.com
# Connect to the host and login using password
open user:pw#address
# get all the files in the remote directory and download them to a specific local directory
lcd C:\Users\xx\Desktop
get *.xlsx
# Close and terminate the session
exit
I searched online and found out that I can put these codes in a bat file and use
Call Shell("cmd.exe /c C:\Users\xx\Desktop\WinSCPGet.bat", 1)
However, only the first line of the bat file WinSCP.com is being executed. It will pop up the cmd window, showing this, without doing anything else.
How to execute all the lines at one time?
Thanks
The code you have is not a Windows batch file. It's one Windows command followed by WinSCP commands. The first command runs winscp.com application, which then sits and waits for input. If you eventually close it, Windows command interpreter (cmd.exe) will carry on executing the remaining commands, failing most, as they are not Windows commands. See also WinSCP script not executing in batch file and WinSCP FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?
So you either have to save the commands (open to exit) to a WinSCP script file (say script.txt) and execute the script using the /script switch:
Call Shell("C:\path\winscp.com /ini=nul /script=c:\path\script.txt")
Alternatively, specify all commands on WinSCP command line, using the /command switch:
Call Shell("C:\path\winscp.com /ini=nul /command ""open user:pw#address"" ""lcd C:\Users\xx\Desktop"" ""get *.xlsx"" ""exit""")
Regarding the quotes: With the /command switch, you have to enclose each command to double-quotes. In VBA string, to use a double-quote, you have to escape it by doubling it.
Also note that you generally should use the /ini=nul switch to isolate the WinSCP script run from your WinSCP configuration. This way you can also make sure that the script will run on other machines. Your script won't, as it lacks the -hostkey switch to verify the SSH host key fingerprint. Using the /ini=nul will help you realize that.
You can have WinSCP GUI generate complete command-line (including the -hostkey) for you.
See also Automating file transfers to SFTP server with WinSCP.
I like this small and compact procedure, and use it in my own projects. No temp-files required. Fast and reliable.
Parse a string src (an absolute filepath) to uploadImageByFTP. Etc. C:\Users\user\Desktop\image.jpg, and the file will be uploaded.
Replace:
<username> with FTP-User
<password> with FTP-Password
<hostname> with FTP-hostname (etc. example.com)
<WinSCP.com path> with path on your WinSCP-client (etc. C:\Program Files (x86)\WinSCP\WinSCP.com. Caution: WinSCP.com and not WinSCP.exe)
<FTP-path> with path on your FTP-client (etc. /httpdocs/wp-content/uploads)
Sub uploadImageByFTP(src As String)
Dim script As Object: Set script = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
'Not empty
If (src <> vbNullString) Then
'Execute script
script.Run _
"""<WinSCP.com path>"" " + _
"/ini=nul " + _
"/command " + _
"""open ftp://<username>:<password>#<hostname>/"" " + _
"""cd <FTP-path>"" " + _
"""put " & """""" & src & """""" & """ " + _
"""close"" " + _
"""exit""", windowStyle, waitOnReturn
End If
End Sub
WScript.Shell is more powerful than the default Shell(), as you can append a waitOnReturn-command; this tells VBA, that further execution isn't allowed before the file(s) have been uploaded to the FTP-server.
Change windowStyle to 0, if you don't like the command prompt to open on each execution.
I'm trying to execute a nodejs command from a vbscript/classic asp page. I'm starting with lessc (less compiler) but need to use other commands too.
nodejs is installed, and I installed lessc in the global namespace (e.g. npm install -g less) I can (at the server cmd prompt) issue lessc and it works.
at the server command prompt, I can issue a command that executes lessc, such as:
lessc D:\webs\player\Layout\less\app.less > D:\webs\player\Layout\less\app.css
but when I execute it thusly inside vbscript:
dim path : path = "D:\webs\player\Layout\less\"
dim shell : shell = server.createobject("WScript.Shell")
dim errCode : errCode = shell.Run("lessc " & path & "\app.less > " & path & "\app.css", 0, true)
response.write errCode
then it does nothing. Substituting the command so that it runs CMD ahead of lessc goes one step forward: it creates a zero byte output file (app.css):
dim errCode : errCode = shell.Run("CMD /C lessc " & path & "\app.less > " & path & "\app.css", 0, true)
So it looks like it's not finding lessc, even though it's defined in the path variable; ECHO %PATH% at the servers command prompt shows the path where lessc is located. So I tried executing the full path to lessc and even that doesn't seem to work ( no errors, no output ):
dim errCode : errCode = shell.Run("CMD /C C:\Users\Administrator\AppData\Roaming\npm\lessc " & path & "\app.less > " & path & "\app.css", 0, true)
.. frustrated now .. I tried piping the output of lessc itself to a file, and it outputs a zero byte file. So it's doing something, just not executing lessc.
call shell.Run("CMD /C C:\Users\Administrator\AppData\Roaming\npm\lessc > c:\temp\lessc.txt", 0, true)
Just how do you get path variables to work in a shell.run anyway? is there a better way to execute a nodejs command server side from in vbscript/classic asp? it's going to be one of those stupid little things I always forget when working with IIS, isn't it?
Well, after a day of mucking about, I came across a github project that has a compressed node and less combo as a standalone package, that is easy to execute just using Shell.Run and you don't have to muck about with environment variables at all.
https://github.com/duncansmart/less.js-windows
So, answered my own question.
I'm using the following winrar command line to create zip archives:
rar.exe a -df -ep -ag[yyyyMMddhhmmss] -ms[txt] C:\MyZipFile.zip C:\tmp\MyFiles*.txt
The archives created are in RAR format instead of ZIP. Is there a way to create regular ZIP and not RAR archives?
Make certain you are using WinRAR.exe and not Rar.exe.
If you are using the command line to do this make sure you type:
winrar a -afzip c:\test.zip c:\test.csv
not:
a -afzip c:\test.zip c:\test.csv
It works for me. I also got it to work in SSIS.
WinRAR has a detailed description of its command line syntax in its help files (WinRAR Help), chapter "Command line syntax".
All the commands such as "a" (add to an archive), "d" (delete from an archive), "e" (extract from an archive ignoring paths) and switches such as "-af" (specify whether to create a rar or a zip file), "-ad" (append archive name to destination path) or "-p" (encrypt the archive using password protection) are listed there.
There are quite a lot of options. I recommend reading the command line syntax rules when working with WinRAR via command lines.
In order to trigger WinRAR zip-packaging from within a MS Access database application, I use in the VBA code for example
Shell c:\Programme\WinRAR\winrar.exe a -afzip -p <AnyPasswordYouLike> "e:\MyStuff\TargetFolder\Output.zip" "e:\MyStuff\SourceFolder\Input.docx"
Of course, the file paths and names are ususally entered via variables, e.g. like
Dim strWinrarCommandline As String
'... and the other variables as well declared in advance, of course...
strWinrarCommandline = strWinrarPathAndSwitches & "-p" & strPassword & " " & Chr(34) & strOutputFullName & Chr(34) & " " & Chr(34) & strInputFullName & Chr(34)
'And then call Winrar simply by:
Shell strWinrarCommandline
So rar.exe is currently unable to create zip files by itself only by calling in the Windows version it is possible.