1

I have read this solution but they all fall into the case of the path which is not my case.

Overcoming the 1024 character limit with setx Basically I created and want to use my environment variable, let's call it MY_VAR which will be quite a long string (for example a credential) When defining this over the web ui in windows it works just fine. But I would like to automate this and do this from the command line. I was exploring the setx and even by using a file for example:

setx MY_VAR /f my_file.txt /a 0,1

WARNING: The length of the extracted value is truncated to 1024 characters.

Extracted value: .... value is correctly displayed.

SUCCESS: Specified value was saved.

I still get said warning even if the extracted value is correct but when I access the variable over "set" I still see it truncated to the 1024 chars.

Is there a way to go around this? Because I can do it from the UI for sure there must be a way to do this from the command line no?

Thanks for any feedback, I know that the question is pretty similar to the one I just linked but honestly all the solutions I see there are very focused on the path but that is not my problem I really just want to define a value that is longer than 1024. I did not explore the part about the registry because honestly I don't know how that works.

5
  • I occasionally store the shorter of two key pairs in a user environment variable, then the longer key in a file stored in my private user profile area (where auditing is enabled). As a work-around, I might suggest changing your MY_VAR to point to the file path location containing your larger data set; as you may get unexpected results relying on environment data larger than 1024 chars, especially with legacy 32-bit apps.
    – leeharvey1
    Feb 24, 2022 at 13:28
  • this is something we want to do for our developers because in our normal setup the keys are stored in secrets and vaults but I can't access the vault from the dev setup so we just have dummy credentials defined locally but I think I'm not aware of how to do them to point to the file. can you explain that a bit better or just point me to one example? Feb 24, 2022 at 13:32
  • Essentially, most developers know how to read the value of an environment variable, and to get the contents of a file. Move the larger [encoded/encrypted] data sets to files (for auditing), then either reference those files via environment variables, or pass the path as arguments to code. If you ever need to decode/decrypt anything in those files (and don't need to audit access), keep shorter data sets in environment variables -- in essence, avoid keeping the two secrets together.
    – leeharvey1
    Feb 24, 2022 at 13:53
  • You cannot use a system variable that is longer than 1024 which is exactly what you are doing by using SETX. You will have to go to your developers and ask for a better solution then using system variables
    – Ramhound
    Feb 24, 2022 at 13:56
  • You could split the value into 2 or more variables. However, you would have to output them 1 at a time as you can't combine variables over said length.
    – cybernard
    Feb 28, 2022 at 19:55

0

You must log in to answer this question.

Browse other questions tagged .