Wednesday, December 27, 2006

QA: IIS and Environment Variable Updates

Question:

Hi,

I want to store uploaded file in a directory C:\Inetpub\Users\Upload. c:\Inetpub is the home directory I have set, so it is pretty much HOME\Users\Upload.

However, when I use following commands, the file is stored in c:\Users\Uoload.

$upload_dir = "$HOME/Users/Upload";
$upload_filename = "$upload_dir/$filename";

if (! open UPLOADFILE, ">$upload_filename")
{
print "error-$!
\n";
}

binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
print UPLOADFILE;
}

close UPLOADFILE;

My question is what am I doing wrong, and is there a predefined variable for home directory ?

Answer:

Sounds like the "HOME" environment variable is not set.

If you just added the environment variable, you need to reboot Windows for it to take effect for an NT service like IIS. This is because NT services like IIS inherit their environment from services.exe, which does not get updated when you change system environment until you reboot.

If you did not just add the HOME environment variable -- then the problem is that the HOME variable does not exist on Windows. The Windows environment variables most similar in function to the *nix HOME variable are HOMEDRIVE and HOMEPATH.

There is a generic way to "update" the environment variables of an NT service WITHOUT rebooting Windows, but it is not guaranteed to work for all services. You can edit:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<ServiceShortName>\Parameters\Environment

and add a String Registry value with a name/value same as the environment variable name/value, i.e. with the command:

REG.EXE add "HKLM\SYSTEM\CurrentControlSet\Services\IISADMIN\Parameters\Environment" /v HOME /t REG_SZ /d "C:\Inetpub" /f

//David

30 comments:

Daniel Williams said...

Drat, I really need to set and use an environment variable without rebooting the system. Is there really no other way to get the var to stick?

Anonymous said...

In your script ...
$ENV{'WHATEVER'} = 'WHATEVER';

The Man said...

I have read a lot of your posts for the last 3 days, but none of them covered exactly what I am looking for. I wonder if you can help with the following please?

We have sent a lot of emails to users, each email contains a URL link. But we are going to change our domain and these links will be broken after a certain date. I've developed an application in C# which is supposed to get the HTTP_REFERER, correct the broken URL and redirects to the correct URL. This application contains a page that's a custom 404 page which is supposed to get the value of the HTTP_REFERER on 404 errors.

The problem is that HTTP_REFERER is always null after IIS redirects to 404 custom error page.

It works with everything else except when IIS redirects to 404.

Hope you understand the problem and hope you can help - thank you.

gurgaonindustry said...

Schools In Gurgaon | Hotels In Gurgaon | Hospitals in Gurgaon | Jewelers In Gurgaon


i like your blog

Anonymous said...

he CORUM STORY-history of the CORUM brand.
http://www.watchestoo.com
replica watches
Men’s watches
Fake watches
watches
IWC
IWC Portuguese Chronograph IW371402
IWC Portuguese CHRONOGRAPH IW371430
IWC Portuguese Chronograph IW371402
IWC Portuguese Chronograph IW371415
IWC Portuguese Chronograph Jackie Chan IW371433
IWC Portuguese FA Jones IW5442-03
IWC Portuguese FAJones IW544202
IWC Portuguese PORTUGUESE CHRONO AUTOMATIC LAUREUS

IW371432

IWC Portuguese Rattapante IW371202
IWC Portuguese REGULATEUR IW5444-01
IWC Portuguese Regulateur IW544404
IWC Portuguese Vintage IW544501C
IWC Portuguese WEMPE IW5443

Unknown said...

lv owners, please listen up. I am spotting a lot of louis vuitton out there that are being misused and mishandled. These precious Louis vuitton bags should be handled like newborn babies. With a gentle touch and lots of love. louis vuitton handbags are some of the most luxurious of all handbags. You have to appreciate the hard work and craftsmanship put into each Louis item.

Unknown said...

People tend to store either images to cherish or official data for future reference. They usually step into SMALL WONDER because of their reliability and durability. There are currently seven different formats available. SMALL WONDER DVD formats are supported by the most of the recorders. Some models also support the Dual Layer formats and the SMALL WONDER DVD COLLECTION . The Symbols in the format has its own significance. It denotes its compatibility and the version.

The coolest of the cool can be seen wearing these multi-functional Ed Hardy clothing . Of course, you can expect ED Hardy Shoes to be as fashionable as the others. Most of the hardy shirt come in vintage designs, making them perfect for everyday wear. You can wear hardy shirts in school, at the mall or even when just chilling out with friends at local hang-outs.

Despite the fact that Hogan scarpe basketball shoes were good shoes to use as Hogan scarpe donna skate shoes many of the skateboarders back then would often reject the idea of using hogan donna for no reason other than the fact that Hogan scarpe uomo were just way to commercial and the skateboarding was supposed to be an underground sport that few people took part in, and most of those people happened to be teenagers.

SEO Boston said...

Website Designers Bostonis one of the leading Boston website design agency.

Website Designers Boston said...

Website Designers Bostonis one of the leading Boston website design agency.

Minnie Mouse Costume said...

Truly amazing, I'd been waiting for such idea like this

Anonymous said...

I really need to set and use an environment variable without rebooting the system.

ovation credit said...

The information you offer gives in depth knowledge.Thanks for such informative article.

regcure reviews said...

Thank you. I just found this blog and what a great resource! It is a good blog and their posts are effective.

Reno Carpet Cleaning said...

Thank you for spending time for such informative post.

razor battery said...

I am happy to see this post. It is really nice and useful for me.

lexington law firm said...

Good post. An excellent resource of information. I will certainly return to check on the latest posts.

Reno Carpet Cleaners said...

You made a number of good points there. I did a search on the theme and found mainly folks will go along with with your blog.

madison wi chiropractor said...

Thank you for sharing excellent informations. Your web-site is very cool. I’m impressed by the details that you’ve on this web site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You…

credit repair texas said...

thanks for the post.

lease audits said...

Finding this site made all the work I did to find it look like nothing. The reason being that this is such an informative post. I wanted to thank you for this informative read of the subject.

sky blue credit repair reviews said...

Thanks for spending the time to discuss this. I feel strongly about it and love reading more on this topic. You are very bright.

rental contract said...

Thanks for your insight for the great posting. I am glad I have taken the time to see this.

history of promissory notes said...

Great post, thanks for sharing this valuable information.

sydney online consultant said...

Thank you for spending time making this blog. It's useful to all of us.

hugopaw said...

Outstanding work. This is very interesting. One of the best blogs I've ever seen. collection agency

DUI School said...

Nice site...

Georgia expungement said...

Thanks for all of the helpful post here.

fix bad credit said...

fix bad credit and save money. Your credit score largely determines the lenders available and the interest rate at which they will lend. Fix credit and expand the number of lenders willing to compete for your loan.

DUI Manslaughter said...

Great and impressive post.

Felony said...

I am so glad this internet thing works and your article really helped me.