Solved

enviroment variables in c#

Posted on 2010-09-07
8
396 Views
Last Modified: 2012-05-10
My application "SC"  is going to exectued standalone on a desktop (the user will enter a username / passwrd to connect to the database) Also it connects via another application that is already logged onto the database.

The question I have is how can i pick up the enviroment variables related to user / password / and database when the application "SC" if executed from another application that is already connected to the oracle database. The other application would be executed from a citrix server if that makes any difference ...

I have tried to use

                test = Environment.GetEnvironmentVariable("USER");

                MessageBox.Show("test = " + test + " \n"
                     , "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

test is always blank wether its from the desktop or from the citrix application
0
Comment
Question by:jhacharya
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Accepted Solution

by:
kris_per earned 300 total points
ID: 33622563

It must be 'USERNAME' (not USER).
0
 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 300 total points
ID: 33622617

This USERNAME will give the user name of the user currently logged into the computer....not the database username...if this is sql server and db login uses windows authentication...then USERNAME is the same for db login...

These are system defined enviornment vars (http://vlaurie.com/computers2/Articles/environment.htm)
OR
Are you saving values in custom environment variabls and then trying to read from another app?

Also the environment where a local app runs and where a citrix app runs are totally different. You can consider it like citrix apps are running in another machine....so you cant really communicate between then using the system environment...but they can communicate using other shared resources like database or shared folder/file...

See if this helps....

0
 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 200 total points
ID: 33625481
when you say username/passwd, currently logged in user to the windows machine or to the DB?
0
 
LVL 2

Author Comment

by:jhacharya
ID: 33627007
the username /password is the oracle database, the application that executes "SC" is a windows gui app and the SC app is a WinFrom written in C#
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 300 total points
ID: 33627511
You can check using the variable name 'USERNAME' (instead of USER) and see what it gives both in local and in citrix. I think it wont be empty and note that it is not oracle username.

Instead of using system environment variable to get the username, etc, you can pass them as command line argument to the SC app and in SC app, get them from command line args as shown in the code below:
In GUIApp - when starting sc app:

{

            string userName = "oracle user name used by the connection";

            string password = "oracle password used by the connection";



            Process scProcess = new Process();

            scProcess.StartInfo.FileName = "sc.exe";

            scProcess.StartInfo.Arguments = userName + " " + password;

            scProcess.Start();



}





In SC app:

{



            // In the place where you want to get username 

            // and password, get them like below:



            string[] arguments = Environment.GetCommandLineArgs();

            string userName = arguments[1];

            string password = arguments[2];



}

Open in new window

0
 
LVL 8

Assisted Solution

by:Gururaj Badam
Gururaj Badam earned 200 total points
ID: 33628594
If i've understood correctly I don't think you will be able to get DB UserName/Passwd from the environment variables unless the caller is setting them explicitly.
0
 
LVL 2

Author Comment

by:jhacharya
ID: 33637056
thanks everyone for the help, it has helped me get to the information i need, in the end i used
what I found was that when the calling program called SC, it had looged onto the oracle database 1st, so the envirment variables where set for that instance, but when SC is called directly from windows you have not logged onto the database and those variableswhere not set


            test = Environment.GetCommandLineArgs();
            for (int i = 0; i < test.GetLength(0); i++)
             {
                 if (test[i].StartsWith("USER="))
                 { luser = test[i].Substring(5); }
                 else if (test[i].StartsWith("PASSWORD="))
                 {  lpswd = test[i].Substring(9); }
                 else if (test[i].StartsWith("DATABASE="))
                 {  ldb = test[i].Substring(9); }
             }
0
 
LVL 2

Author Closing Comment

by:jhacharya
ID: 33640295
gave good pointers and helped me understand what direction to take
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET HttpWebRequest 12 58
Host asp.net pages 5 25
Entity Framework 7 32
Help with C#, MVC, razor. 6 23
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now