Environment vars in a batch file?

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
DocMAX
Newbie
Newbie
Posts: 4
Joined: Fri Jul 25, 2008 6:17 am

Environment vars in a batch file?

Post by DocMAX »

Hello,

i use a batch file like this to "redirect" appdata for each individual app/game like this:

Code: Select all

@echo off
set "APPDATA=%~dp0_data\User\AppData\Roaming"
set "ALLUSERSPROFILE=%~dp0_data\ProgramData"
set "HOMEPATH=%~dp0_data\User"
set "LOCALAPPDATA=%~dp0_data\User\AppData\Local"
set "ProgramData=%~dp0_data\ProgramData"
set "USERPROFILE=%~dp0_data\User"
set "PUBLIC=%~dp0_data\Public"

if not exist "%APPDATA%" ( md "%APPDATA%")
if not exist "%ALLUSERSPROFILE%" ( md "%ALLUSERSPROFILE%")
if not exist "%HOMEPATH%" ( md "%HOMEPATH%")
if not exist "%LOCALAPPDATA%" ( md "%LOCALAPPDATA%")
if not exist "%USERPROFILE%" ( md "%USERPROFILE%")
if not exist "%PUBLIC%" ( md "%PUBLIC%")

if not exist "%USERPROFILE%\Desktop" (
	md "%USERPROFILE%\Desktop"
	)

if not exist "%USERPROFILE%\Documents" (
	md "%USERPROFILE%\Documents"
	)

if not exist "%PUBLIC%\Documents" (
	md "%PUBLIC%\Documents"
	)

start "" "%~dp0Ace7Game.exe"
It works in Windows but not in wine. The game does not use the env var.
Can this be fixed to have the same behaviour like in windows?

Thanks,
DocMAX
jkfloris
Level 12
Level 12
Posts: 3141
Joined: Thu Aug 14, 2014 10:10 am

Re: Environment vars in a batch file?

Post by jkfloris »

Do you mean the batch script doesn't work or the program doesn't use the changed variables?
You can check the functionality of the batch script with set.

Code: Select all

wine cmd
# Change to the batch script directory if necessary
# c:
# cd path\to\batch\file\directory

# Check the current variables
set

# run the batch file
batch_file.bat

# Check if the variables have changed
set
DocMAX
Newbie
Newbie
Posts: 4
Joined: Fri Jul 25, 2008 6:17 am

Re: Environment vars in a batch file?

Post by DocMAX »

The program does not use the changes variables. I also have checked the variables with "set".
They changed, but the programm doesn't use them.
Also did this with a AutoHotKey script. Doesn't work either.
The apps write in the usual AppData directories.
jkfloris
Level 12
Level 12
Posts: 3141
Joined: Thu Aug 14, 2014 10:10 am

Re: Environment vars in a batch file?

Post by jkfloris »

You're right. At least Wine does not change the APPDATA variable like Windows 11 does.
Please file a bug


Wine:

Code: Select all

C:\test>test.bat
Appdata at the start: C:\users\floris\AppData\Roaming
Appdata after set: C:\test\_data\User\AppData\Roaming
011c:fixme:ntdll:NtQuerySystemInformation info_class SYSTEM_PERFORMANCE_INFORMATION
AppData is: C:\users\floris\AppData\Roaming
Windows

Code: Select all

C:\test>test.bat
Appdata at the start: C:\Users\floris\AppData\Roaming
Appdata after set: C:\test\_data\User\AppData\Roaming
AppData is: C:\test\_data\User\AppData\Roaming
test.bat

Code: Select all

@echo off
echo Appdata at the start: %APPDATA%

set "APPDATA=%~dp0_data\User\AppData\Roaming"
set "ALLUSERSPROFILE=%~dp0_data\ProgramData"
set "HOMEPATH=%~dp0_data\User"
set "LOCALAPPDATA=%~dp0_data\User\AppData\Local"
set "ProgramData=%~dp0_data\ProgramData"
set "USERPROFILE=%~dp0_data\User"
set "PUBLIC=%~dp0_data\Public"

if not exist "%APPDATA%" ( md "%APPDATA%")
if not exist "%ALLUSERSPROFILE%" ( md "%ALLUSERSPROFILE%")
if not exist "%HOMEPATH%" ( md "%HOMEPATH%")
if not exist "%LOCALAPPDATA%" ( md "%LOCALAPPDATA%")
if not exist "%USERPROFILE%" ( md "%USERPROFILE%")
if not exist "%PUBLIC%" ( md "%PUBLIC%")

if not exist "%USERPROFILE%\Desktop" (
	md "%USERPROFILE%\Desktop"
	)

if not exist "%USERPROFILE%\Documents" (
	md "%USERPROFILE%\Documents"
	)

if not exist "%PUBLIC%\Documents" (
	md "%PUBLIC%\Documents"
	)


echo Appdata after set: %APPDATA%

"%~dp0test.exe"
test.exe

Code: Select all

using System;

class Program {
    static void Main(string[] args) {
        string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        
        Console.WriteLine("AppData is: " + appDataFolder);
    }
}
Locked