Need help to connect Unix through Excel - vba

As Part of data Analysis, I need to connect excel macros with unix, fire my shell script from a macro, and get the output file back to excel. I tried using winsock, but it didn't work

This is not a very clear question...
but i suggest to split the problem into parts
test the shell script to make sure it outputs exactly what you want (including carriage returns / whitespace / other fromatting that might confuse Windows or Excel)
test your method of connecting from Windows to Unix. make sure you can run a command from PowerShell which logs in to the unix machine, runs the script, and returns the result
test your Excel macro. ensure it has permission to make the connection you made from PowerShell
You'll have better luck on StackOverflow if you post a piece of code (or network details) and the error message you got from that code.

Related

Access VBA: Shell command broken in one particular database

I have two Access databases that I'm opening on the same computer. In one, running this in the immediate window works as expected (opens Notepad):
Shell "notepad.exe"
In the other, I get this error instead:
Run-time error '5': Invalid procedure call or argument
I have not been able to come up with any shell command that will run successfully in that second database. No matter what, I get that error.
What is going on here? Could there be a security setting coming into play? Or perhaps one is an older version?
Edit - More Info
When I go to the definition of Shell in the malfunctioning database, it goes to VBA.Interaction.Shell.
I get the correct IntelliSense tooltip for Shell.
I tried VBA.Shell "notepad.exe" and VBA.Interaction.Shell "notepad.exe" without success (same error).
Here are the references that are checked in both databases:
Decompiling did not help.
The culprit was our anti-virus software! UGH!
Why did it work in one database and not the other then? I'm told that years ago, anti-virus exceptions were made for my computer for the one database but not the other.
I recommend that any others who encounter this problem check their anti-virus logs/policies. Also, running the database from another computer with different policies in place might shed some light on the issue faster. In this case, when I used remote desktop to log into a server, I was able to call shell successfully.

Process.Start does not always work

I created a protocol generation tool that reads some data from a websource, allows the user to filter some of the fields an generate a protocol based on given filterdata. The protocol is generated as a word document that is edited multiple times, on multiple layers, before shown to the user.
For some users the line:
Process.Start(pathtowordfile)
does not open Word, for others it works fine.
Even more strange: if the useres try to generate the protocol the first time it opens. if they change one of the filters and generate again, the file does not open. But it is generated correctly, you are able to open it manually.
We are using Windows 7 on all machines and, in general, the User has no administrativ privileges on the machine.
Are there any alternatives to
Process.Start()
?
Not sure how the code can sometimes work, but the critical bit I think would be to make sure you set UseShellExecute=true when you are trying to Process.Start a file that is not an executable.
https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute%28v=vs.110%29.aspx
I haven't looked into it in quite awhile, but last I checked shell execute relies on the Word application to be properly registered with DDE so Windows knows what to do with a .doc(x) file. Word may not be installed "properly".
after trying varios things, including Wonko's hint, I dicided to use the interop.Word.Wordapplication to display the document. It doesn't explain why process.start not does the job but anyway, now everybody of the users is happy^^

VB program works fine when stepping through but crashes when ran with the .exe

This is a weird persistant issue I am having with a small visual basic program.
Problem: The excutable of the vb program crashes when trying to run but when I step through the program inside of visual studio it runs successfully.
Details: The program performs a winscp.com transfer from a ftp server and then takes the downloaded file and extracts the data from it before sending it to a webpage. The program also decrypts a des3 encrypted file which holds the login details for the sftp server and the webpage.
My Thoughts: I was thinking this could be something to do with the excutable jumping ahead of the slower transfer and decrypt functions thus causing a "file not found" exception to be produced and the program to exit. Lending to this if I slowly (aka spend 10+ seconds stepping through the code) move through the code it works just fine.
Solution: I was thinking of including some kind of checks inside the program to make sure that the file exsists before moving on but I still wanted to get your guys opinion.
Thanks!
As requested
Crash Messages:
(I capture everything in exceptions and exit properly so no "crash" is reported but the error I get in my logs is as follows:)
1st run with standard test case:
Could not find file 'C:\Users\Administrator\Desktop..\ILC2INFOENC.txt'
2nd run standard case (the file above was not deleted by my cleanup function either as it could not be found)
Could not find file 'C:\Users\Administrator\Desktop..\ILCNETSL10663.csv'
Background:
The first file that is found missing is the encrypted login information file while the second file is the winscp.com downloaded csv file.
Thanks again for all the help and suggestions.
Solution: Applied checks to the existance of the files in question as to keep the vb program from jumping ahead of the slower moning openssl decrypt and the winscp file transfer. If I had the time to redo this portion of code I would have utilized the .net framework provided sftp function and the decrypter instead of winscp and openssl as to better control the flow of the program! If you need more options check below the original question for different takes of this issue.

Running a Command that will run on every computer

I have this code which gives me all of the information I need regarding tasks, information etc. I have it all shelled into a VB program and I want to be able to run this from one computer and have it return the data from all computers on the domain.
I am lost as to what to add next.
Dim sCommand As String
'all processes here, ipconfig, java info, etc etc
sCommand = "java.exe -version2 > C:\Info.txt && ipconfig >> C:\INfo.txt"
Shell("cmd.exe /c" & sCommand)
I have script that will list all users on the domain, can I implement that or is there an easier way?
Edit: If I could search the entire domain for a specific file that would work too.
At the moment I just need all the data returned to a text file, I am not worried about it being sorted, or how long a process like this would take.
thanks a bunch
You could do one of two things.
1) You could use WMI to get both the network config off the remote machines and execute a process on the remote machine.
Or
2) You could use PsExec to kick off a command on a remote machine and pipe that out. I personally wouldn't use shell to execute a command as it's pretty poor really. If I was going to kick off a process locally I'd use this, and use StdOut to grab the output from the shell, parse it to give you something you can work with instead of piping the output to a file locally and then reading it later.
EDIT
So you want to do all this from one central location? If you don't want to use PSExec, you'll have to use WMI to create a process on a remote machine to run the java.exe, but you can't redirect the output, you'll have to pipe to a file and read the file in another step.

ms-access: doing repetitive processes with vba/sql

i have an access database backend that contains three tables. i have distributed the front end to several users. this is a very simple database with minimal functionality. i need to import certain rows from a file every hour into one of the tables in the database. i would like to know what is the best way to automate this process so that i can have it running hourly. i need it to be running sort of as a service in the background. can you tell me how you would do this?
You could have for example:
a ms-access file with all necessary code to run the import proc
a BAT file containing the command line(s) that will run this ms-access file with all requested parameters. Check ms-access command line parameters to see the available options.
a task scheduler service software to launch the BAT file: depending on the task scheduler and the command line to be sent, you could even avoid the BAT file step
If all you want to do is run some queries, I would not do this by automating all of Access, but instead by writing a VBScript that uses DAO to execute the SQL directly. That's a much more efficient way to do it, and will run without a console logon (which may or may not be required for full Access to be run by the task scheduler).