Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:16:06+00:00 2026-06-15T10:16:06+00:00

Ok i got this basic IF-statement. I want to set a user role, based

  • 0

Ok i got this basic IF-statement. I want to set a user role, based on it’s username. It does look like though, that the set statement never gets executed and therefore i got an empty echo.

if "%username%" == "admin" (
    set role = "admin"
) else (
    set role = "user"
)

echo %role%

Did I miss something or may it be that Windows just does not support that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:16:08+00:00Added an answer on June 15, 2026 at 10:16 am

    Remove the spaces. You are now setting a value to the environment variable role (with a trailing space that Stack Overflow won’t show). Also, the role becomes "admin" (including quotes and a leading space, that is, again, not visible here).

    You can verify this by running set without parameters from the command line. It will give you a list of all variables, in which you can clearly see the undesired spaces.

    if "%username%" == "admin" (
        set role=admin
    ) else (
        set role=user
    )
    
    echo %role%
    

    The only reason you still need quotes with an if statement, is that the statement would become invalid if %username% didn’t exist/was empty. In that case, the line would become:

    if == admin (
    

    … Which is of course invalid. It doesn’t even need to be quotes, you could also write:

    if %username%XYZ == adminXYZ (
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this really basic table structure: Posts PostXTags PostTags There is a 1-n
Got this site with UN/PW set via the Createuserwizard control. Client considers PW too
This question is so basic that I'm almost embarrassed to ask it, but it's
Ok, I would like to use a CASE STATEMENT for this, but I am
this is some basic IF THEN statement stuff but I'm a coding newbie so
I got this basic doubt. The STL header doesn't have .h extension. #include <vector>
I got this really basic code with options for Fancybox: $(document).ready(function() { $(.publications a).fancybox({
I got very basic question. Why this is not working?! <?xml version=1.0 encoding=utf-8?> <s:Application
I've got this basic model, where a provision object, a nested resource of a
I've Got a Window with this basic layout: <Window MinHeight=72 MaxHeight=400 Height=Auto MinWidth=460 MaxWidth=460>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.