AppData\Roaming folder in windows service project - windows

I need a help on getting Special folder in windows service program. I used this code in my Windows Form application:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
and got the path, ""C:\Users\\AppData\Roaming"*
But if I run the same code in my Winows Service project I got the path: "C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\"
But I need the earlier path (got in Windows Form). How do I get the same path in Service projet also.
I have user setting file, log, config file in the "C:\Users\\AppData\Roaming" folder. So I have to refer the same path both in my Windows Form application and Windows Service project.
Can somebody tell me, what is the difference here and how do i get the same path in both type of project?
Thanks,
sharath

Your Windows Service should use 'User' Account, instead of 'LocalService' or 'LocalSystem'.
ServiceProcessInstaller process = new ServiceProcessInstaller();
process.Account = ServiceAccount.User;
And during installation of the service, you need to specify the username and password of currently logged in user. Username should be in this format: "MachineName\UserName". Example: ".\John"

Related

Not able to set the GOOGLE_APPLICATION_CREDENTIALS environment variable for Google.Cloud.Translation in xamarin forms

I'm trying to use Google.Cloud.Translation service of Google Cloud platform (GCP) for the translation of text in Xamarin forms. I want to translate my application from English to Arabic. I enabled the API. Created a json file from the Service account. Followed the step in the following url
https://cloud.google.com/translate/docs/setup
But still when I try to set the GOOGLE_APPLICATION_CREDENTIALS I get exception-
Error reading credential file from location
C:/Users/xxx/Downloads/xxxx-280817-bedb566bfd11.json: Could not find a part of the path "/C:/Users/xxxx/Downloads/xxxx-280817-bedb566bfd11.json". Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS
I have tried numerous ways to fix this. This is my code:
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS","C:/Users/xxx/Downloads/xx-280817-bedb566bfd11.json");
TranslationClient client = TranslationClient.Create();
How can I fix this, so I can have translation of English to Arabic language in my Xamarin form?
Put your GOOGLE_APPLICATION_CREDENTIALS json file as EmbeddedResource and you can get yout path by this way
<ItemGroup>
<EmbeddedResource Include="_fonts/OpenSans.ttf" />
</ItemGroup>
to get the file path
var assembly = typeof(MyLibrary.MyClass).GetTypeInfo().Assembly;
Stream resource = assembly.GetManifestResourceStream("MyLibrary._fonts.OpenSans.ttf");
The key point is to use the right name on GetManifestResourceStream call. You have to use [assembly name].[directory].[file name].
Ref link: https://stackoverflow.com/a/41106851/4778712
The issue you are having is that the Application Default Credentials are not available.
They are available if running in Google Compute Engine, otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined on your local machine, pointing to a file defining the credentials as shown here.
So how to you define it?
If you are using a Mac and you place the json file in the Downloads folder, you would open your Terminal app and run this command in it:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/xx-280817-bedb566bfd11.json"
It seems like you are using a Windows computer and you placed the file in your Downloads folder, so you would open your "Windows Command Prompt" (type CMD in Run, or search for Command Prompt) and run this command:
set GOOGLE_APPLICATION_CREDENTIALS="C:\Users\xxx\Downloads\xx-280817-bedb566bfd11.json"
Make sure that the xx-280817-bedb566bfd11.json is the correct file name of the JSON file that contains your service account key.
You could get the service account key in the Google Cloud Platform Console as shown here.

How to set application name and installation path while installing by AdminApp?

Just tried this thing for a day or two, able to do the installation using AdminApp command, but still got some problem about application name and installation path.
Reference I look from IBM said AppName is defined by display name, I think that mean it use the display name field from web.xml? But the result that I see is the application name will look like "Test_AP.war16dfd74ab1a", not exactly the same.
The installation path parameter part is also ambiguous, I don't think I see a thing looks like it.
https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.iseries.doc/ae/rxml_taskoptions.html?view=embed#rxml_taskoptions__cmd10
import time
AdminApp.install('C:/Users/Development/Desktop/Test_AP.war', '-cell WIN-9DAB2SINode01Cell')
AdminConfig.save()
result = AdminApp.isAppReady('Test_AP')
while (result == "false"):
### Wait 5 seconds before checking again
time.sleep(5)
result = AdminApp.isAppReady('Test_AP')
print("Starting application...")
What I try to achieve is to use this script to install my service onto WAS with exact application name(same as my WAR name or display name in web.xml) and designated installation path, then start the service. But now I'm stuck at com.ibm.ws.scripting.ScriptingException: WASX7280E: An application with name "Test_AP_WAR" does not exist. Can anyone tell me how to do this?
Simple Solution
You need to include an -appname argument such as:
AdminApp.install('C:/Users/Development/Desktop/Test_AP.war', ['-cell WIN-9DAB2SINode01Cell' -appname SimpleTestConnection5_war])
Otherwise WAS will generate an application name for you.
Ideal Solution
Create an AdminApp.install command using the Admin Console. Install an enterprise application using the WAS Admin Console. On the last page, you will see a help box in the upper right corner. Click on view administrative scripting and you will be provided with an AdminApp.install command. This command can be edited with a custom location and appname.

classic asp create text file on webserver: error 800a0034 Bad_file_name_or_number

I have a classic asp page in VBS and I am trying to create a file on the web server with the following code.
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.CreateTextFile("\\localhost\inetpub\wwwroot\cs\batch\123456dirs.bat", true)
This returns the following error:
|666|800a0034|Bad_file_name_or_number
Line 666 is the CreateTextFile line.
According to the Microsoft docs, this means that I'm trying to create a file with an invalid filename. Then it explains the rules for filenames and mine appears to be perfectly valid.
Any suggestions or ideas on how I can further troubleshoot this?
first thing to check to make sure your users have access to the folder. Assuming you're not using windows authentication, make sure IUSR account has write access to the folder.
second, unless inetpub is set up as a share to folder, you're syntax won't work. if the root of your website is located in the CS folder, you can do something like:
Set file1 = fso.CreateTextFile(Server.MapPath( "/cs/batch/123456dirs.bat" ), true)
The createtextfile() function runs on the web server but in the context of the local server itself. Simply put, any path you give it must resolve as if you were logged on to a windows desktop on the server and tried to CD to that path.
The format \localhost... is a UNC path. See this question for a discussion about UNC paths and windows. Unless you know for sure that there is a UNC path mapped for \localhost then that is probably your issue. You may be making the assumption the \localhost will be a reasonable path to use, but as I said unless you know for sure it is available then this is an invalid choice.
Lastly, if you decide to set up a share for \localhost, you will be getting in to some interesting territory around the user context that the web server operates in. You see you will have to set up the share for the IIS user that is configured as the run-as identity for IIS, so you will need to know that and create the required config to give that user the share.
If it were me, I would switch to using a standard windows path, although even then you need to appreciate the run-as user context and security config, etc.

WSAdmin - Admin App Install: Random string is appended to the Application name

I am working on automation script to install a WAR in the Websphere using WSADMIN console. It leaves random string at the end of the application name.
If the application name is 'test.war', name appears as 'test.war1525e76b1cb'. Has anyone come across this issue before? Any solutions worked. I need the application name to match the artifact to use isAppReady and start the application.
I believe not providing specific app name appends random string to the artifact name and sets as application display name. This line of code with -appname option did the trick.
AdminApp.install(appPath,['-appname '+app_name+'','-MapWebModToVH', [['.*', '.*', 'default_host']]])

Request Write Permission on Web Setup

In the File System Editor under the Web Setup project I have
witch says that my Sripts folder should have Write Access ... but once installed I do not have the user IIS_USR/IIS_WPG (Anonymous User or/and Worker Process) in that folder, and for such, no write access to that folder when used from a hosted level.
This is what I get:
but I should have this:
AllowWriteAccess is used by IIS Web Properties dialog. It's not used to set permissions on the actual folder on disk. Your folder will use default permissions when installed.
To set custom permissions you can try using XCACLS.EXE as a custom action.

Resources