Concatenating value to a command line - vb.net

I am making a program that uses the rasidal command to connect to a VPN server. Obviously this requires a login and this is stored in a notepad file.
Process.Start("rasdial.exe", """VPN Connection"" HardcodedUSERNAME HardCodedPassword")
This seems to work fine, however when I read this information from a notepad file and write it to the screen they are still exactly the same. Why is it that the login could be incorrect.
All I am doing is
Process.Start("rasdial.exe", """VPN Connection"" & Info")
Thanks

Your variable "info" is never used. Try it out an remove the info-variable or rename it.
Do you have to double-quote "VPN Connection"? So try this one:
Process.Start("rasdial.exe", """VPN Connection"" " & Info)
And can you please tell me what your info-variable contains.

Related

How can I run a bat file with spaces in the filepath?

I want to run a bat file used to compile sass to css from within a Kotlin program, on a Windows machine. I had everything working using Runtime.exec until I switched to a Windows account that had a space in the username. From what I read, I read that using ProcessBuilder would make this easier. It seems that even with ProcessBuilder I still can't get it to work, no matter what I try.
Here is my code so far
val commands = mutableListOf(
"cmd",
"/c",
"C:\\Users\\John Doe\\VCS\\test\\tools\\sass\\windows\\dart-sass\\sass.bat",
"--no-source-map",
"C:\\Users\\John Doe\\VCS\\test\\src\\main\\sass\\global.scss",
"global.css"
)
val processBuilder = ProcessBuilder(commands)
val process = processBuilder.start()
...
The error I get is 'C:\Users\John' is not recognized as an internal or external command, operable program or batch file. It doesn't help if I surround the strings that have spaces with \".
If I remember correctly, all windows files and folders that have a space in the name have a matching short name in the old 8.3 format replacing additional space and other characters with a tilde (~) and a number.
So whatever is returning you the path for the .bat and .sscs files could return the full filename in that format?
Doesn't solve the problem but avoids it instead, I admit.
Also means you won't get busted when someone puts a space in the filename (OK, unlikely, but still something better to deal with from the start).
Consider something along the lines of the top 2 answers on this superuser thread
This is actually a Windows cmd issue. The question here shows that in cmd, in addition to quoting the file paths, you also have to quote the entire part of the command line text after the /c switch.
I don't know if this is the best way to do it in ProcessBuilder, but I was able to get it to work with the following code.
"cmd.exe",
"/c",
"\"\"C:/Users/John Doe/VCS/test/tools/sass/windows/dart-sass/sass.bat\" "
+ "--no-source-map "
+ "\"C:/Users/John Doe/VCS/test/src/main/sass/global.scss\" "
+ "\"global.css\"\""

Set Kettle DB Connection password from Environment Variable

How do I set a database connection's password to use an environment variable. I cannot add these to the kettle.properties file (security policy). When I click control-space on OSX, nothing happens. If I try and paste the string ${PASSWORD} directly into the password field, it does not allow it, due to the presumably non-alphanumeric '$' char.
The other fields as shown below work fine.
The EDIT Connection dialog below shows the field in red, which is what I want to achieve logically.
Using PDI Community 8.2, on Mac OSX Mojave.
I found one solution. Instead of creating the DB connection in Table Input Step with Edit or New, I used the Wizard option, which allowed me to paste ${SOURCE_DB_PASSWORD} variable into the password field.
The characters were obfuscated, so it's impossible to tell if you have the correct value, but it worked.
CTRL+V doesn’t work, you need to right-click and choose paste.
You can encrypt the password and save it on kettle.properties, in spoon directory execute:
Encr.bat -kettle yourpassword
Paste the full result with "Encrypted" in the properties file, restart spoon and test the connection.
In OSX, I believe you need to use the shortcut shift + cmd + space to access the environment variables.
You might need to use the 'get variables'-step to define the variables from kettle.properties.
Just type ${Variable_Name} as you are defining for other environment variable. If open your .ktr file in Notepad++ you can see the value is your Variable_Name instead of Encrypted password. It worked for me :)
enter image description here

Use gpg to pass the passphrase file to decrypt the files

I need use shell to pass the passphrase from a file, and want the comment line can read the passphrase from this file, --passphrase-fd is not working for me. It's always output an error "can not find the file". I debug the output and input files, and they are correct. Is might be the passphrase.cat file, but I checked, there is no problem in the file. Any problem in the comment line??
my code as follows and thanks for any help:
Shell(pgp & "--passphrase -fd 0 <C:\Temp\test.txt" & " -output " & output & "--decrypt " & input & """", AppWinStyle.Hide, True) ' the error happens here.
End If
''' The error as follows:
''' Unable to complete the request: System.IO.FileNotFoundException: File not found. at Microsoft.VisualBasic.Interaction.Shell(String PathName, AppWinStyle Style, Boolean Wait, Int32 Timeout) at the Sign_Click(object sender, EventArgs e) in C:\sign\MainForm.vb:line361
I expect a whole bunch of issues. For further debugging, print the command to the command line instead of executing it with Shell(...).
I guess the pgp variable does not end with a space, thus the application tries to execute something like C:\path\to\gnupg\gpg.exe--passphrase instead of C:\path\to\gnupg\gpg.exe with --passphrase parameter
The same issue likely exists between the output variable and the --decrypt command
There may not be a space inside --passphrase-fd, you wrote passphrase -fd
--output is a long parameter and requires two dashes (you wrote -output)
Finally, I figured it out. Have to use -passphrase-file passwordfile.txt to decrypted my file in the application.

PostgreSQL setting pg_hba.config file

I am pretty new to databases and also using the command prompt. I've been trying to create a database but first I believe I need to set the pg_hba.config file. When I open SQL shell it says"
Server [localhost]:
ENTER
Database[postgres]:
ENTER
Port [5432]:
ENTER
Username [postgres]:
ENTER
Password for user postgres:
And then it won't let me type anything there, so I'm not really sure what to do from here.
It looks like you're on Windows, and you're starting psql.
When you type the password it's receiving it, but it's just not showing the characters as a security measure. It's like replacing the characters with bullets.
Just type the password and press enter.

Error trying rename a file

Hi community!
I have an application in VB.Net, in the user's computer is located in program files.
The users run always the program as an Administrators.
But in some cases; when the program try to rename a file in the program files the program throws the following exception:
The given path's format is not supported.
SOURCE = System.Security.Util.StringExpressionSet.CanonicalizePath
Also, happens when I try to copy a file.
The application does the rename or copy automatically and it's the same name for all the users
Example:
Rename(vOld, vNew)
FileCopy(vOld, vNew)
This exception only happen in Win7.
Somebody have an idea what is the reason to some users appear this exception?
This will happen when the user provides an invalid file name, for example one that includes colons.
You should validate that the user-entered file name does not contain any of the values in System.IO.Path.GetInvalidPathChars.
All it's my fault!
-_-'
I'm trying to rename this path:
C:\_MyFile.xlsx
To:
C:\MyFile.xlsx
In my computer all works fine because I have the both files (The users only has the file with the underscore).
When the program try to validate it try to rename the file "_C:\MyFile.xlsx" to "C:\MyFile.xlsx"
The exception don't give much information about my error...