I am new here. I took C++ as one of my school requirements and I found it interesting. I am currently working on a program that will allow me to remote connect to users computers.
I want usrname to take my input and then I want the program to pass the value of usrname to system("vncviewer.exe -AutoSelect=0 -lowcolourlevel=2 usrname");
If I understood you well, in line 16 you need to say for example: system("vncviewer.exe -AutoSelect=0 -lowcolourlevel=2 carlos");
(username is variable in this line)
don't forget that system takes a char* parameter (constchar* to be precise)
so you can do:
The reason being is that computer name is not based on the user but it is based on the department. (carlospc is just an example) This is why I did the following:
1 2
string carlos = "carlospc";
string james = "jamespc";
So when I enter carlos, the program will know to call:
To my knowledge this is not possible like that.
However I think that If you put the user name and the computer name in a bi-dimensional string array you would be able to do it.
So you'll find the computer name based on the user name and do like what I said in my previous post.
Hope this help!
OK, I am genuinely confused now. You are including the 'windows.h' header file and not 'cstdlib', but you are using the "system()" function instead of "CreateProcess()" to launch VNC... Why would you do this?
Side Note: You can also send the password on the command line when you launch vncviewer with the "/password" switch. I wasn't sure if you knew that and just left it out or what but I thought I would mention it.
Something to add to your project later:
You're already including the 'windows.h' header so you should be able to link to the 'AdvApi32.lib' and also include 'WinSvc.h' without having do download anything additional. Before you make what ever call you decide on to launch the vncviewer app you should probably make sure that it has something to connect to on the other side, right? To do this you'll want to call the "OpenSCManager()" and feed it the target PC's name, which you already have since you need it to launch vncviewer. If "OpenSCManager()" succeeds it returns a 'SC_HANDLE' object to the target PC's Service Control Manager which you should then use as an argument to the "OpenService()" function along with the name of the VNC Server service (I'll save you the trip to Google, it's 'winvnc' without the quotes). The "OpenService()" function (again if it succeeds) returns a different 'SC_HANDLE' object that matches up with that service on the target machine, you will use this with the "QueryService()" function to fill out the 'SERVICE_STATUS' struct and tell you if the service is up and running. If it is then great, on you go, but if it is not then you will want to start it up again won't you? This is done by passing the same 'SC_HANDLE' object that was returned from the "OpenService()" function to the function called "StartService()", the return code from that function will tell you if it worked or not.
I wrote this up to illustrate how easy it is to do something like interact with a remote computer using the WinAPI. This is to encourage you try doing things the right way and stop using this "system()" call crap. Also, feel free to check out the Windows section of the forum if you have questions about stuff like this.
Jewellcpp: Thanks for your response. I will look into it.
Computergeek01:
OK, I am genuinely confused now. You are including the 'windows.h' header file and not 'cstdlib', but you are using the "system()" function instead of "CreateProcess()" to launch VNC... Why would you do this?
Because I am using however I learned in my C++ class. As you can see on my first post, I am stating that I took 1 c++ class. I am not a program nor I want to be. I am a sys admin who would like to make my life easier.
Side Note: You can also send the password on the command line when you launch vncviewer with the "/password" switch. I wasn't sure if you knew that and just left it out or what but I thought I would mention it.
I knew that... for security reasons, I don't. In case someone takes the program and runs it. And I know what you might say "vnc is not secure" well, I use it for my internal network and we are behind a firewall. Also, I have a complex password setup on each machine.
I wrote this up to illustrate how easy it is to do something like interact with a remote computer using the WinAPI. This is to encourage you try doing things the right way and stop using this "system()" call crap. Also, feel free to check out the Windows section of the forum if you have questions about stuff like this.
As stated before, I am using whatever my teacher taught me. I am not a programmer. I will look into your suggestion.