473,811 Members | 3,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to distinguish between system environment variablesand the user ones?

To a environment variable in Windows, can python know if it is a
system environment
variable or a current-user environment variable?
--
ðÐðÄ´ÏÃ÷¾ø¶¥¡¢¸ ãЦ֮¼«£¬ÊÇÈËÀà µÄºÃÅóÓÑ¡£
Ö±µ½ÓÐÒ»Ì죬ÎÒ² Å·¢¾õ£¬ÎÒÊÇðÐðÄ ¡£
ÎÒÊÇ·*ǽµÄðÐðÄ¡ £
Jul 18 '05 #1
2 1413
could ildg wrote:
To a environment variable in Windows, can python know if it is a
system environment
variable or a current-user environment variable?


Not just by using the "os.environ " approach.
You would have to resort to the "pywin32"
extensions. Check the Python Cookbook using
Google for "environmen t variable" recipes and
you'll get a good start on it.

You'll also require a bit of Win32-specific
knowledge, since this entire concept is not
a cross-platform one.

-Peter
Jul 18 '05 #2
There is nothing that plainly differentiates whether an environment
variable is the system's or the current user's.

What you could do is:
1. Get the list of environment variables for the user the script is
executing as.
2. Use the pywin32 extensions to access the registry key
HKCU\Environmen t
3. Lookup the environment variables present in the list (Item 1) that
appear as string values under HKCU\Environmen t.
4. The intersecting list belongs to the user, the rest can be surmised
as belonging to the system environment.

Thanks,
--Kartic

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2151
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in edit mode. The reason I want to do this is becasue when entering a new record the form is entered in data entry mode and I have lots of stuff happening upon entering and leaving fields. In edit mode I do not want the events to fire.
2
2199
by: Nick Gilbert | last post by:
Hi I have a number of pages where it is valid for the user to enter HTML. On these pages, I have turned off RequestValidation ("ValidateRequest = false" in the page directive) so that the HttpRequestValidationException that gets thrown if HTML is included in the Form, doesn't get thrown. This is fine. However, on some of those pages, there are fields where I don't want
8
596
by: BVS | last post by:
I am moving from c++ to c# and I have been converting code to c# I have not been able to convert the following code: SYSTEM_INFO siSysInfo; GetSystemInfo(&siSysInfo); SystemID = siSysInfo.dwOemId.ToString(); ProcessorType = siSysInfo.dwProcessorType.ToString(); ProcessorMask = siSysInfo.dwActiveProcessorMask.ToString();
35
2447
by: nobody | last post by:
I need to pop up a modal JS-based dialog (for some reason can't use popup window, much less so showModalDialog()), and I'd like to imitate the system popup titlebar according to user's desktop settings (classic, XP, Vista). No big deal to make it work, but how do I know the style to display? Any chance to figure out these settings programmatically either on the client (preferrable), or possibly in asp.net from something like Request (not...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5565
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.